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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
git_borg_linker
Commits
ab140d7d
Verified
Commit
ab140d7d
authored
2 years ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/pull.rs src/push.rs: update of get_remote_dir
parent
0a13aedc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pull.rs
+1
-1
1 addition, 1 deletion
src/pull.rs
src/push.rs
+38
-20
38 additions, 20 deletions
src/push.rs
with
39 additions
and
21 deletions
src/pull.rs
+
1
−
1
View file @
ab140d7d
...
...
@@ -273,7 +273,7 @@ pub fn pull(remote: &str) -> () {
let
(
borg_folder
,
_
)
=
commit
::
check_path
();
let
borg_folder
=
borg_folder
.canonicalize
()
.unwrap
();
push
::
check_dest_and_copy
(
&
borg_folder
,
&
url
,
&
adress
);
let
remote_dir
=
push
::
get_remote_dir
(
&
url
,
&
borg_folder
);
let
remote_dir
=
push
::
get_remote_dir
(
&
url
);
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"
);
...
...
This diff is collapsed.
Click to expand it.
src/push.rs
+
38
−
20
View file @
ab140d7d
use
crate
::
commit
;
use
crate
::
configt
;
use
crate
::
list
;
use
crate
::
remote
;
use
colored
::
Colorize
;
...
...
@@ -173,7 +174,6 @@ fn get_id(content: &str) -> String {
my_id
}
/// Get the current project id
/// # Return
/// The id inside .borg/config file
...
...
@@ -204,7 +204,6 @@ fn compare_id(remote_dir: &PathBuf, adress: &str) -> (bool, String, String) {
(
current_id
==
distant_id
,
current_id
,
distant_id
)
}
/// Asks the user a question and get the answer
/// # Arguments:
/// - `question`: The question asked to a user
...
...
@@ -307,7 +306,16 @@ fn check_dir_exist_local(remote_dir: &PathBuf) -> bool {
remote_dir
.is_dir
()
}
/// Function that check if a file exist on a remote filesystem
/// Function that check if a file exist on the local filesystem
/// # Arguments
/// - `remote_file`: The remote file located inside the remote
/// # Return
/// true if the `remote_dir` is a directory, false else
fn
check_file_exist_local
(
remote_file
:
&
PathBuf
)
->
bool
{
remote_file
.is_file
()
}
/// Function that check if a dir exist on a remote filesystem
/// # Arguments
/// - `remote_dir`: The remote dir located by the remote
/// - `adress`: The adress of the remote folder
...
...
@@ -336,7 +344,21 @@ fn check_file_exist_remote(remote_tar: &PathBuf, adress: &str) -> bool {
/// - `adress`: The adress of the remote folder
/// # Return
/// true if the `remote_dir` is a directory, false else
fn
check_dir_exist
(
remote_dir
:
&
PathBuf
,
adress
:
&
str
)
->
bool
{
pub
(
crate
)
fn
check_file_exist
(
remote_dir
:
&
PathBuf
,
adress
:
&
str
)
->
bool
{
if
adress
==
"file"
{
check_file_exist_local
(
remote_dir
)
}
else
{
check_file_exist_remote
(
remote_dir
,
adress
)
}
}
/// Function that check if a dir exist on a remote or the local filesystem
/// # Arguments
/// - `remote_dir`: The remote dir located by the remote
/// - `adress`: The adress of the remote folder
/// # Return
/// true if the `remote_dir` is a directory, false else
pub
(
crate
)
fn
check_dir_exist
(
remote_dir
:
&
PathBuf
,
adress
:
&
str
)
->
bool
{
if
adress
==
"file"
{
check_dir_exist_local
(
remote_dir
)
}
else
{
...
...
@@ -424,13 +446,19 @@ fn get_remote_path(remote: &str) -> String {
/// - `url`: A complete url path in adress:path form
/// # Return
/// A tuple containing the adress and the url
fn
split_path
(
url
:
&
str
)
->
(
String
,
PathBuf
)
{
pub
(
crate
)
fn
split_path
(
url
:
&
str
)
->
(
String
,
PathBuf
)
{
let
res
=
url
.split
(
":"
)
.collect
::
<
Vec
<&
str
>>
();
if
res
.len
()
==
1
{
return
(
String
::
from
(
"file"
),
PathBuf
::
from
(
url
));
return
(
String
::
from
(
"file"
),
PathBuf
::
from
(
url
)
.canonicalize
()
.unwrap
(),
);
}
else
if
res
.len
()
==
2
{
if
res
[
0
]
.to_lowercase
()
==
"file"
{
return
(
String
::
from
(
"file"
),
PathBuf
::
from
(
res
[
1
]));
return
(
String
::
from
(
"file"
),
PathBuf
::
from
(
res
[
1
])
.canonicalize
()
.unwrap
(),
);
}
return
(
res
[
0
]
.to_owned
(),
PathBuf
::
from
(
res
[
1
]));
}
...
...
@@ -557,7 +585,6 @@ pub(crate) fn copy_file(
};
}
/// Function that return the name of the folder that will containg the content
/// of the .borg folder on the remote directory
///
...
...
@@ -566,18 +593,9 @@ pub(crate) fn copy_file(
/// # Return
/// The path `url/borg_archive_<PROJECT_DIR>` where <PROJECT_DIR> is the name
/// of the folder at the root of the project
pub
(
crate
)
fn
get_remote_dir
(
url
:
&
PathBuf
,
borg_folder
:
&
PathBuf
)
->
PathBuf
{
pub
(
crate
)
fn
get_remote_dir
(
url
:
&
PathBuf
)
->
PathBuf
{
let
mut
remote_dir
=
url
.to_owned
();
let
name_folder
=
format!
(
"borg-archive_{}"
,
borg_folder
.parent
()
.unwrap
()
.file_stem
()
.unwrap
()
.to_str
()
.unwrap
()
);
let
name_folder
=
configt
::
get_project_name
();
remote_dir
.push
(
name_folder
);
remote_dir
}
...
...
@@ -590,7 +608,7 @@ pub fn push(remote: &str) -> () {
let
borg_folder
=
borg_folder
.canonicalize
()
.unwrap
();
let
(
adress
,
url
)
=
get_adress_and_url
(
remote
);
check_dest_and_copy
(
&
borg_folder
,
&
url
,
&
adress
);
let
remote_dir
=
get_remote_dir
(
&
url
,
&
borg_folder
);
let
remote_dir
=
get_remote_dir
(
&
url
);
handle_existing_remote_dir
(
&
remote_dir
,
&
adress
,
"push"
);
copy_file
(
&
borg_folder
,
&
remote_dir
,
&
adress
,
"push"
);
}
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