Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
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
Service Desk
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
octobus
Poulpe
Commits
be651cc5
Commit
be651cc5
authored
3 years ago
by
Simon Sapin
Browse files
Options
Downloads
Patches
Plain Diff
Add --overwrite CLI option
parent
88251c94
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Initial implementation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+17
-4
17 additions, 4 deletions
src/main.rs
with
17 additions
and
4 deletions
src/main.rs
+
17
−
4
View file @
be651cc5
...
...
@@ -18,6 +18,10 @@
#[structopt(long)]
no_confirm
:
bool
,
/// Overwrite a dataset archive with the same name if it exists
#[structopt(long)]
overwrite
:
bool
,
/// The directory to archive.
/// The dataset name is taken from the last component of this path.
directory
:
PathBuf
,
...
...
@@ -32,7 +36,7 @@
impl
NewDataset
{
fn
run
(
&
self
,
megafine
:
&
Megafine
)
->
Result
<
()
>
{
println!
(
"
Creating a
dataset from directory {}"
,
"
New
dataset from directory {}"
,
style
(
self
.directory
.display
())
.bold
()
);
if
!
std
::
fs
::
metadata
(
&
self
.directory
)
?
.is_dir
()
{
...
...
@@ -65,6 +69,12 @@
let
archive_path
=
megafine
.tmp_dir
.join
(
&
archive_name
);
if
archive_path
.exists
()
{
Err
(
format!
(
"tmp/{} already exists"
,
bold
))
?
if
self
.overwrite
{
println!
(
"Overwriting tmp/{}"
,
bold
)
}
else
{
Err
(
format!
(
"tmp/{} already exists"
,
bold
))
?
}
}
else
{
println!
(
"Creating tmp/{}"
,
bold
);
}
...
...
@@ -69,6 +79,5 @@
}
println!
(
"About to create tmp/{}"
,
bold
);
if
!
self
.no_confirm
{
let
proceed
=
Confirm
::
new
()
.with_prompt
(
"Continue?"
)
...
...
@@ -93,7 +102,11 @@
let
Tee
(
mut
tmp_file
,
sha
)
=
zstd
.finish
()
?
;
let
size
=
tmp_file
.stream_position
()
?
;
tmp_file
.as_file_mut
()
.sync_all
()
?
;
tmp_file
.persist_noclobber
(
&
archive_path
)
?
;
if
self
.overwrite
{
tmp_file
.persist
(
&
archive_path
)
?
;
}
else
{
tmp_file
.persist_noclobber
(
&
archive_path
)
?
;
}
let
hash
=
hex
::
encode
(
sha
.finalize
());
println!
(
"Compressed to {}"
,
style
(
BinaryBytes
(
size
))
.bold
());
...
...
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