Skip to content

Commit 2d0c77c

Browse files
v0.1.1 - deal with privileged files
1 parent 9c753fd commit 2d0c77c

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Don't worry, they're easy to remember after a minute:
3232

3333
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.
3434

35+
**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.
36+
3537
## Additional commands and flags
3638

3739
`bak down --keep my_file` - Restores from .bakfile, does not delete .bakfile

Diff for: bak/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BAK_VERSION = "0.1.0a1"
1+
BAK_VERSION = "0.1.1a1"

Diff for: bak/commands/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ def bak_up_cmd(filename: Path):
225225
db_handler.update_bakfile_entry(old_bakfile)
226226
return True
227227

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

229233
def bak_down_cmd(filename: Path,
230234
destination: Optional[Path],
@@ -270,7 +274,11 @@ def bak_down_cmd(filename: Path,
270274
if not confirm:
271275
console.print("Cancelled.")
272276
return
273-
copy2(bakfile_entry.bakfile_loc, destination)
277+
278+
try:
279+
copy2(bakfile_entry.bakfile_loc, destination)
280+
except PermissionError:
281+
_sudo_bak_down_helper(bakfile_entry.bakfile_loc, destination)
274282
if not keep_bakfile:
275283
for entry in bakfile_entries:
276284
Path(entry.bakfile_loc).unlink(missing_ok=True)

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'rich==9.1.0']
99

1010
setup(name='bak',
11-
version='0.1.0a1',
11+
version='0.1.1a1',
1212
description='the .bak manager',
1313
author='ChanceNCounter',
1414
author_email='[email protected]',

0 commit comments

Comments
 (0)