Merge pull request #10209 from filecoin-project/fix-check-backupfile
fix: cli: error if backup file already exists
This commit is contained in:
commit
9848e0467e
@ -61,6 +61,10 @@ func BackupCmd(repoFlag string, rt repo.RepoType, getApi BackupApiFn) *cli.Comma
|
|||||||
return xerrors.Errorf("expanding file path: %w", err)
|
return xerrors.Errorf("expanding file path: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(fpath); !os.IsNotExist(err) {
|
||||||
|
return xerrors.Errorf("backup file %s already exists. Overwriting it will corrupt the file, please specify another file name", fpath)
|
||||||
|
}
|
||||||
|
|
||||||
out, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY, 0644)
|
out, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("opening backup file %s: %w", fpath, err)
|
return xerrors.Errorf("opening backup file %s: %w", fpath, err)
|
||||||
@ -87,7 +91,12 @@ func BackupCmd(repoFlag string, rt repo.RepoType, getApi BackupApiFn) *cli.Comma
|
|||||||
}
|
}
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
err = api.CreateBackup(ReqContext(cctx), cctx.Args().First())
|
backupPath := cctx.Args().First()
|
||||||
|
if _, err := os.Stat(backupPath); !os.IsNotExist(err) {
|
||||||
|
return xerrors.Errorf("backup file %s already exists. Overwriting it will corrupt the file, please specify another file name", backupPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = api.CreateBackup(ReqContext(cctx), backupPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user