Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Clash Verge
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Clash Verge
Commits
9c4a46bc
There was an error fetching the commit references. Please try again later.
Unverified
Commit
9c4a46bc
authored
2 years ago
by
John Smith
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: escape the space in path (#451)
parent
52658886
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src-tauri/src/core/manager.rs
+35
-1
35 additions, 1 deletion
src-tauri/src/core/manager.rs
with
35 additions
and
1 deletion
src-tauri/src/core/manager.rs
+
35
−
1
View file @
9c4a46bc
use
std
::
borrow
::
Cow
;
/// 给clash内核的tun模式授权
#[cfg(any(target_os
=
"macos"
,
target_os
=
"linux"
))]
pub
fn
grant_permission
(
core
:
String
)
->
anyhow
::
Result
<
()
>
{
...
...
@@ -5,12 +7,15 @@ pub fn grant_permission(core: String) -> anyhow::Result<()> {
use
tauri
::
utils
::
platform
::
current_exe
;
let
path
=
current_exe
()
?
.with_file_name
(
core
)
.canonicalize
()
?
;
let
path
=
path
.display
();
let
path
=
path
.display
()
.to_string
()
;
log
::
debug!
(
"grant_permission path: {path}"
);
#[cfg(target_os
=
"macos"
)]
let
output
=
{
// the path of clash /Applications/Clash Verge.app/Contents/MacOS/clash
// https://apple.stackexchange.com/questions/82967/problem-with-empty-spaces-when-executing-shell-commands-in-applescript
let
path
=
escape
(
&
path
);
let
shell
=
format!
(
"chown root:admin {path}
\n
chmod +sx {path}"
);
let
command
=
format!
(
r#"do shell script "{shell}" with administrator privileges"#
);
Command
::
new
(
"osascript"
)
...
...
@@ -35,3 +40,32 @@ pub fn grant_permission(core: String) -> anyhow::Result<()> {
anyhow
::
bail!
(
"{stderr}"
);
}
}
pub
fn
escape
<
'a
>
(
text
:
&
'a
str
)
->
Cow
<
'a
,
str
>
{
let
bytes
=
text
.as_bytes
();
let
mut
owned
=
None
;
for
pos
in
0
..
bytes
.len
()
{
let
special
=
match
bytes
[
pos
]
{
b' '
=>
Some
(
b' '
),
_
=>
None
,
};
if
let
Some
(
s
)
=
special
{
if
owned
.is_none
()
{
owned
=
Some
(
bytes
[
0
..
pos
]
.to_owned
());
}
owned
.as_mut
()
.unwrap
()
.push
(
b'\\'
);
owned
.as_mut
()
.unwrap
()
.push
(
b'\\'
);
owned
.as_mut
()
.unwrap
()
.push
(
s
);
}
else
if
let
Some
(
owned
)
=
owned
.as_mut
()
{
owned
.push
(
bytes
[
pos
]);
}
}
if
let
Some
(
owned
)
=
owned
{
unsafe
{
Cow
::
Owned
(
String
::
from_utf8_unchecked
(
owned
))
}
}
else
{
unsafe
{
Cow
::
Borrowed
(
std
::
str
::
from_utf8_unchecked
(
bytes
))
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment