Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion audbackend/core/backend/artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,16 @@ def _put_file(
src_path: str,
dst_path: str,
checksum: str,
owner: str,
verbose: bool,
):
r"""Put file to backend."""
r"""Put file to backend.

``owner`` is ignored,
as Artifactory derives the owner
from the user uploading the file.

"""
dst_path = self.path(dst_path)
_deploy(src_path, dst_path, checksum, verbose=verbose)

Expand Down
10 changes: 10 additions & 0 deletions audbackend/core/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ def _put_file(
src_path: str,
dst_path: str,
checksum: str,
owner: str,
verbose: bool,
): # pragma: no cover
r"""Put file to backend."""
Expand All @@ -1325,6 +1326,7 @@ def put_file(
src_path: str,
dst_path: str,
*,
owner: str = None,
validate: bool = False,
verbose: bool = False,
):
Expand All @@ -1345,6 +1347,13 @@ def put_file(
Args:
src_path: path to local file
dst_path: path to file on backend
owner: owner to store with the file.
Only backends that track ownership
as custom metadata
(e.g. :class:`audbackend.backend.Minio`)
make use of this.
If ``None``,
the current user is stored as owner
validate: verify file was successfully
put on the backend
verbose: show debug messages
Expand Down Expand Up @@ -1378,6 +1387,7 @@ def put_file(
src_path,
dst_path,
checksum,
owner,
verbose,
)

Expand Down
9 changes: 8 additions & 1 deletion audbackend/core/backend/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,16 @@ def _put_file(
src_path: str,
dst_path: str,
checksum: str,
owner: str,
verbose: bool,
):
r"""Put file to backend."""
r"""Put file to backend.

``owner`` is ignored,
as the owner is derived
from the file system.

"""
dst_path = self._expand(dst_path)
audeer.mkdir(os.path.dirname(dst_path))
shutil.copy(src_path, dst_path)
Expand Down
19 changes: 13 additions & 6 deletions audbackend/core/backend/minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _copy_file(
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = audeer.path(tmp_dir, os.path.basename(src_path))
self._get_file(src_path, tmp_path, num_workers, verbose)
self._put_file(tmp_path, dst_path, checksum, verbose)
self._put_file(tmp_path, dst_path, checksum, None, verbose)
else:
self._client.copy_object(
bucket_name=self.repository,
Expand Down Expand Up @@ -534,6 +534,7 @@ def _put_file(
src_path: str,
dst_path: str,
checksum: str,
owner: str,
verbose: bool,
):
r"""Put file to backend."""
Expand All @@ -551,7 +552,7 @@ def _put_file(
object_name=dst_path,
file_path=src_path,
content_type=content_type,
metadata=_metadata(checksum),
metadata=_metadata(checksum, owner),
)

if verbose: # pragma: no cover
Expand Down Expand Up @@ -587,18 +588,24 @@ def _size(
return size


def _metadata(checksum: str):
"""Dictionary with owner entry.
def _metadata(checksum: str, owner: str = None):
"""Dictionary with checksum and owner entries.

When uploaded as metadata to MinIO,
it can be accessed under ``stat_object(...).metadata["x-amz-meta-owner"]``.
the owner can be accessed under
``stat_object(...).metadata["x-amz-meta-owner"]``.

Args:
checksum: checksum to be stored in metadata
owner: owner to be stored in metadata.
If ``None`` or empty,
the current user is used
"""
if not owner:
owner = getpass.getuser()
return {
"checksum": checksum,
"owner": getpass.getuser(),
"owner": owner,
}


Expand Down
9 changes: 9 additions & 0 deletions audbackend/core/interface/unversioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ def put_file(
src_path: str,
dst_path: str,
*,
owner: str = None,
validate: bool = False,
verbose: bool = False,
):
Expand All @@ -644,6 +645,13 @@ def put_file(
Args:
src_path: path to local file
dst_path: path to file on backend
owner: owner to store with the file.
Only backends that track ownership
as custom metadata
(e.g. :class:`audbackend.backend.Minio`)
make use of this.
If ``None``,
the current user is stored as owner
validate: verify file was successfully
put on the backend
verbose: show debug messages
Expand Down Expand Up @@ -673,6 +681,7 @@ def put_file(
self.backend.put_file(
src_path,
dst_path,
owner=owner,
validate=validate,
verbose=verbose,
)
Expand Down
9 changes: 9 additions & 0 deletions audbackend/core/interface/versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ def put_file(
dst_path: str,
version: str,
*,
owner: str = None,
validate: bool = False,
verbose: bool = False,
):
Expand All @@ -825,6 +826,13 @@ def put_file(
src_path: path to local file
dst_path: path to file on backend
version: version string
owner: owner to store with the file.
Only backends that track ownership
as custom metadata
(e.g. :class:`audbackend.backend.Minio`)
make use of this.
If ``None``,
the current user is stored as owner
validate: verify file was successfully
put on the backend
verbose: show debug messages
Expand Down Expand Up @@ -860,6 +868,7 @@ def put_file(
return self.backend.put_file(
src_path,
dst_path_with_version,
owner=owner,
validate=validate,
verbose=verbose,
)
Expand Down
4 changes: 3 additions & 1 deletion docs/developer-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ a file to our backend.
src_path: str,
dst_path: str,
checksum: str,
owner: str,
verbose: bool,
):
with self._db as db:
Expand All @@ -366,7 +367,8 @@ a file to our backend.
INSERT INTO data (path, checksum, content, date, owner)
VALUES (?, ?, ?, ?, ?)
"""
owner = getpass.getuser()
if not owner:
owner = getpass.getuser()
date = datetime.datetime.today().strftime("%Y-%m-%d")
data = (dst_path, checksum, content, date, owner)
db.execute(query, data)
Expand Down
2 changes: 2 additions & 0 deletions tests/bad_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def put_file(
src_path: str,
dst_path: str,
*,
owner: str = None,
validate: bool = False,
verbose: bool = False,
):
Expand All @@ -22,6 +23,7 @@ def put_file(
src_path,
dst_path,
checksum,
owner,
verbose,
)

Expand Down
1 change: 1 addition & 0 deletions tests/singlefolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def _put_file(
src_path: str,
dst_path: str,
checksum: str,
owner: str,
verbose: bool,
):
with self.Map(self._path, self._lock) as m:
Expand Down
Loading