Browse Source

Add reflink support for unlinkable files and a set of all property

files processed that can be safely skipped
master
Raphael Roberts 5 years ago
parent
commit
16310ed2c7
  1. 1
      requirements.txt
  2. 25
      tibi_hardlinks/__init__.py
  3. 21
      tibi_hardlinks/backups.py

1
requirements.txt

@ -2,3 +2,4 @@ pytz
python-dateutil
PyYAML
appdirs
reflink

25
tibi_hardlinks/__init__.py

@ -16,19 +16,24 @@ def find_all_property_files():
def hardlink_all_files(files, dry=False):
for prop_file in files:
backup = Backup(prop_file)
dest_dir = create_backup_directory_name(
backup.backup_info, CONFIG_DATA["customization"]["time_format"]
)
dest_dir = Path(CONFIG_DATA["output"]["output_root"]) / dest_dir
if dry:
print(f"mkdir: {dest_dir}")
else:
dest_dir.mkdir(parents=True, exist_ok=True)
backup.hardlink_to(dest_dir, dry)
try:
already_processed = cache_manager.tibi_cache["already_processed"]
except KeyError:
already_processed = set()
cache_manager.tibi_cache["already_processed"] = already_processed
cache_manager.tibi_cache.sync()
if prop_file not in already_processed:
backup = Backup(prop_file)
dest_dir = create_backup_directory_name(
backup.backup_info, CONFIG_DATA["customization"]["time_format"]
)
dest_dir = Path(CONFIG_DATA["output"]["output_root"]) / dest_dir
if not dest_dir.exists():
if dry:
print(f"mkdir: {dest_dir}")
else:
dest_dir.mkdir(parents=True)
backup.hardlink_to(dest_dir, dry)
def main():

21
tibi_hardlinks/backups.py

@ -1,5 +1,8 @@
from pathlib import Path
import datetime
import re
from reflink import reflink
from tibi_hardlinks.backup_parser import read_backup_properties
from tibi_hardlinks.exceptions import ConfigurationException
@ -99,8 +102,18 @@ class Backup:
for filepath in self.related_files.values():
if filepath:
filename = filepath.name
if dry:
print(f'link: "{filepath}" => "{dest_dir / filename}"')
else:
filepath.link_to(dest_dir / filename)
dest_path = dest_dir / filename
can_skip = True
if not dest_path.exists():
can_skip = False
if dry:
print(f'link: "{filepath}" => "{dest_path}"')
else:
try:
filepath.link_to(dest_path)
except OSError:
reflink(str(filepath), str(dest_path))
except Exception:
raise
if can_skip and not dry:
cache_manager.tibi_cache["already_processed"].add(self.property_file)
Loading…
Cancel
Save