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
496ef0b2
Commit
496ef0b2
authored
Sep 1, 2022
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/mount.rs: add mount module to display old archive version
parent
3ebc805e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mount.rs
+66
-0
66 additions, 0 deletions
src/mount.rs
with
66 additions
and
0 deletions
src/mount.rs
0 → 100644
+
66
−
0
View file @
496ef0b2
use
crate
::
commit
;
use
std
::
fs
;
use
std
::
path
::
PathBuf
;
use
std
::
process
::{
exit
,
Command
};
/// Get the path of the .mount folder
///
/// # Description
/// Get the path of the .mount folder at the root of the project folder. if it
/// doesn't exits, then creates it
fn
get_mount_folder
(
borgfolder
:
&
PathBuf
)
->
PathBuf
{
let
mut
mount_folder
=
borgfolder
.parent
()
.unwrap
()
.to_path_buf
();
mount_folder
.push
(
".mount"
);
if
!
mount_folder
.is_dir
()
{
fs
::
create_dir
(
&
mount_folder
)
.expect
(
"Unable to create .mount directory"
);
}
mount_folder
}
pub
fn
mount_archive
(
commit
:
&
Option
<
String
>
,
path
:
&
Option
<
String
>
,
versions
:
bool
)
->
()
{
let
(
borg_folder
,
_
)
=
commit
::
check_path
();
let
mount_folder
=
get_mount_folder
(
&
borg_folder
);
let
globp
=
match
commit
{
Some
(
g
)
=>
format!
(
"-a '{}'"
,
g
),
None
=>
String
::
from
(
""
),
};
let
mp
=
match
path
{
Some
(
p
)
=>
String
::
from
(
p
),
None
=>
String
::
from
(
""
),
};
let
vopt
=
match
versions
{
true
=>
String
::
from
(
"-o versions"
),
false
=>
String
::
from
(
""
),
};
let
cmd
=
format!
(
"borg mount {} {} {} {} {}"
,
globp
,
vopt
,
borg_folder
.to_str
()
.unwrap
(),
mount_folder
.to_str
()
.unwrap
(),
mp
);
let
output
=
Command
::
new
(
"sh"
)
.arg
(
"-c"
)
.arg
(
cmd
)
.output
()
.unwrap
();
match
output
.status
.code
()
.unwrap
()
{
0
=>
(),
num
=>
{
eprintln!
(
"{}"
,
String
::
from_utf8
(
output
.stderr
)
.unwrap
());
exit
(
num
);
}
}
}
/// Unount an borg archive mounted in .mount folder
pub
fn
umount_archive
()
->
()
{
let
(
borg_folder
,
_
)
=
commit
::
check_path
();
let
mount_folder
=
get_mount_folder
(
&
borg_folder
);
let
cmd
=
format!
(
"borg umount {}"
,
mount_folder
.to_str
()
.unwrap
());
let
output
=
Command
::
new
(
"sh"
)
.arg
(
"-c"
)
.arg
(
cmd
)
.output
()
.unwrap
();
match
output
.status
.code
()
.unwrap
()
{
0
=>
(),
num
=>
{
eprintln!
(
"{}"
,
String
::
from_utf8
(
output
.stderr
)
.unwrap
());
exit
(
num
);
}
}
}
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