Skip to content

Commit

Permalink
Change logic in housekeeper add file. Remove function link_to_houseke…
Browse files Browse the repository at this point in the history
…eper_path.
  • Loading branch information
beatrizsavinhas committed Jan 15, 2025
1 parent 3c3a354 commit 964ac78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 8 additions & 2 deletions housekeeper/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from housekeeper.date import get_date
from housekeeper.exc import VersionIncludedError
from housekeeper.files import load_json, validate_input
from housekeeper.include import include_version, link_to_relative_path, relative_path
from housekeeper.include import include_version, relative_path, link_file
from housekeeper.store.models import Bundle, Tag, Version
from housekeeper.store.store import Store

Expand Down Expand Up @@ -133,7 +133,13 @@ def file_cmd(
tags = data.get("tags", tags)
if not keep_input_path:
version: Version = bundle.versions[0]
link_to_relative_path(version=version, file_path=file_path, root_path=context.obj[ROOT])
housekeeper_file_path: Path = Path(context.obj[ROOT], version.relative_root_dir, file_path.name)
if housekeeper_file_path.exists():
if not Path.samefile(housekeeper_file_path, path):
LOG.warning("A file with the same name already exists in %s.", file_path)
raise click.Abort
else:
link_file(file_path=file_path, new_path=housekeeper_file_path, hardlink=True)
file_path: Path = relative_path(version=version, file=file_path)
new_file = store.add_file(file_path=file_path, bundle=bundle, tags=tags)
store.session.add(new_file)
Expand Down
6 changes: 0 additions & 6 deletions housekeeper/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,5 @@ def checksum(path: Path) -> str:
return hasher.hexdigest()


def link_to_relative_path(file_path: Path, root_path: Path, version: Version) -> None:
"""Link the given absolute path to its path when included in the given version and return the relative path."""
housekeeper_path: Path = Path(root_path, version.relative_root_dir, file_path.name)
link_file(file_path=file_path, new_path=housekeeper_path, hardlink=True)


def relative_path(version: Version, file: Path) -> Path:
return Path(version.relative_root_dir, file.name)

0 comments on commit 964ac78

Please sign in to comment.