Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git_borg_linker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
git_borg_linker
Commits
0922bae8
Verified
Commit
0922bae8
authored
Jan 31, 2023
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/pull.rs: add function used to bypass borg security
parent
2a0f72d4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pull.rs
+122
-1
122 additions, 1 deletion
src/pull.rs
with
122 additions
and
1 deletion
src/pull.rs
+
122
−
1
View file @
0922bae8
...
...
@@ -3,7 +3,7 @@ use crate::mount::file_diff;
use
crate
::
push
;
use
colored
::
Colorize
;
use
std
::
path
::
PathBuf
;
use
std
::
process
::
exit
;
use
std
::
process
::
{
exit
,
Command
,
Stdio
}
;
pub
(
crate
)
fn
get_savefolder
(
borg_folder
:
&
PathBuf
)
->
PathBuf
{
let
mut
save_dir
=
file_diff
::
get_tmp_folder
(
borg_folder
);
...
...
@@ -99,6 +99,125 @@ fn save_and_clean_borg_folder(borg_folder: &PathBuf) {
}
}
fn
check_ok
(
path_str
:
&
str
)
->
PathBuf
{
let
path
=
PathBuf
::
from
(
path_str
);
if
!
path
.is_dir
()
{
eprintln!
(
"{}: {} is not a directory !"
,
"error:"
.red
(),
path
.display
()
);
exit
(
1
)
}
else
{
return
path
;
}
}
/// Get the base dir
fn
get_base_dir
()
->
PathBuf
{
let
base_dir
=
std
::
env
::
var
(
"BORG_BASE_DIR"
);
match
base_dir
{
Ok
(
dir
)
=>
check_ok
(
&
dir
),
Err
(
_
)
=>
{
let
base_dir
=
std
::
env
::
var
(
"HOME"
);
match
base_dir
{
Ok
(
dir
)
=>
check_ok
(
&
dir
),
Err
(
_
)
=>
{
eprintln!
(
"{}: HOME environment variable not set !"
,
"error"
.red
());
exit
(
1
);
}
}
}
}
}
/// This function get the config borg directory
fn
get_config_dir
()
->
PathBuf
{
let
mut
config
=
get_base_dir
();
config
.push
(
".config"
);
let
mut
new_config
=
if
!
std
::
env
::
var
(
"BORG_BASE_DIR"
)
.is_ok
()
{
let
new_config
=
match
std
::
env
::
var
(
"XDG_CONFIG_HOME"
)
{
Ok
(
p
)
=>
check_ok
(
&
p
),
Err
(
_
)
=>
config
,
};
new_config
}
else
{
config
};
new_config
.push
(
"borg"
);
let
config_path
=
match
std
::
env
::
var
(
"BORG_CONFIG_DIR"
)
{
Ok
(
p
)
=>
check_ok
(
&
p
),
Err
(
_
)
=>
new_config
,
};
if
!
config_path
.is_dir
()
{
eprintln!
(
"{}: Failed to get borg config dir"
,
&
config_path
.display
());
exit
(
1
);
}
config_path
}
/// This function aims to get the borg security dir
fn
get_security_dir
()
->
PathBuf
{
let
security_dir
=
std
::
env
::
var
(
"BORG_SECURITY_DIR"
);
match
security_dir
{
Ok
(
dir
)
=>
check_ok
(
&
dir
),
Err
(
_
)
=>
{
let
mut
path
=
get_config_dir
();
path
.push
(
"security"
);
return
path
;
}
}
}
/// Get the timestamp manifest for the current borg project
/// # Return
/// A file corresponding to the timestamp manifest of the project folder
fn
get_manifest_timestamp
(
security_dir
:
PathBuf
)
->
PathBuf
{
let
current_id
=
push
::
get_project_id
();
let
mut
security_dir
=
security_dir
;
security_dir
.push
(
current_id
);
security_dir
.push
(
"manifest-timestamp"
);
if
!
security_dir
.is_file
()
{
eprintln!
(
"{}: {} is not a file !"
,
"error"
.red
(),
&
security_dir
.display
()
);
exit
(
1
);
};
security_dir
}
/// Function that remove the manifest-timestamp
fn
remove_manifest_timestamp
()
{
let
security_dir
=
get_security_dir
();
let
manifest
=
get_manifest_timestamp
(
security_dir
);
std
::
fs
::
remove_file
(
&
manifest
)
.expect
(
&
format!
(
"{}: Unable to delete {}"
,
"error"
.red
(),
&
manifest
.display
()
));
}
/// Function that removes .borg cache
/// # Arguments
/// - `borg_folder`: The .borg folder of the current project
fn
borg_delete_cache
(
borg_folder
:
&
PathBuf
)
{
let
args
=
vec!
[
"delete"
,
"--cache-only"
,
borg_folder
.to_str
()
.unwrap
()];
let
mut
output
=
Command
::
new
(
"borg"
)
.args
(
&
args
)
.stdout
(
Stdio
::
inherit
())
.stdin
(
Stdio
::
inherit
())
.spawn
()
.unwrap
();
match
output
.wait
()
{
Err
(
e
)
=>
{
eprintln!
(
"{}: borg terminaned with an error: {}"
,
"error"
.red
(),
e
);
exit
(
1
);
}
Ok
(
_
)
=>
(),
}
}
/// Create a push the tar achive on the selected remote path
/// # Arguments
...
...
@@ -112,4 +231,6 @@ pub fn pull(remote: &str) -> () {
push
::
handle_existing_remote_dir
(
&
remote_dir
,
&
adress
,
"pull"
);
save_and_clean_borg_folder
(
&
borg_folder
);
push
::
copy_file
(
&
borg_folder
,
&
remote_dir
,
&
adress
,
"pull"
);
remove_manifest_timestamp
();
borg_delete_cache
(
&
borg_folder
);
}
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