Skip to content

Commit

Permalink
v0.1.1 - deal with privileged files
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanceNCounter authored Feb 25, 2021
1 parent 9c753fd commit 2d0c77c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Don't worry, they're easy to remember after a minute:

All of **bak**'s commands will disambiguate between multiple copies of the same file. In other words, you can `bak my_thing.txt` as many times as you want, until you're finished working, if you'd prefer to keep multiples instead of using `bak up`. At the moment, all you've got to go by are timestamps when it asks you to pick a .bakfile, but this will improve.

**NOTE:** `bak down` will fall back on `sudo cp` if necessary. Please don't run `sudo bak`. This may create parallel config and bakfiles in root's XDG directories.

## Additional commands and flags

`bak down --keep my_file` - Restores from .bakfile, does not delete .bakfile
Expand Down
2 changes: 1 addition & 1 deletion bak/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BAK_VERSION = "0.1.0a1"
BAK_VERSION = "0.1.1a1"
10 changes: 9 additions & 1 deletion bak/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def bak_up_cmd(filename: Path):
db_handler.update_bakfile_entry(old_bakfile)
return True

def _sudo_bak_down_helper(src, dest):
# TODO spin this off into a separate exec for sanity
click.echo(f"The destination {dest} is privileged. Falling back on 'sudo cp'")
call(f"sudo cp {src} {dest}".split(" "))

def bak_down_cmd(filename: Path,
destination: Optional[Path],
Expand Down Expand Up @@ -270,7 +274,11 @@ def bak_down_cmd(filename: Path,
if not confirm:
console.print("Cancelled.")
return
copy2(bakfile_entry.bakfile_loc, destination)

try:
copy2(bakfile_entry.bakfile_loc, destination)
except PermissionError:
_sudo_bak_down_helper(bakfile_entry.bakfile_loc, destination)
if not keep_bakfile:
for entry in bakfile_entries:
Path(entry.bakfile_loc).unlink(missing_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'rich==9.1.0']

setup(name='bak',
version='0.1.0a1',
version='0.1.1a1',
description='the .bak manager',
author='ChanceNCounter',
author_email='[email protected]',
Expand Down

0 comments on commit 2d0c77c

Please sign in to comment.