Skip to content

Commit 29ad412

Browse files
serialization: skip ignored files before checking for symlinks (#550)
Ignored files aren't serialized, so they shouldn't raise a ValueError if allow_symlinks wasn't set. Signed-off-by: Spencer Schrock <[email protected]>
1 parent 8807bad commit 29ad412

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ All versions prior to 1.0.0 are untracked.
1616
- ...
1717

1818
### Fixed
19-
- ...
19+
- Fixed a bug where ignored symlinks could raise `ValueError`s if allow_symlinks was unset, even though they were skipped during serialization. ([#550](https://github.com/sigstore/model-transparency/pull/550))
2020

2121
### Removed
2222
- ...

src/model_signing/_serialization/file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ def serialize(
111111
(model_path,), model_path.glob("**/*")
112112
)
113113
for path in files_to_hash:
114+
if serialization.should_ignore(path, ignore_paths):
115+
continue
114116
serialization.check_file_or_directory(
115117
path, allow_symlinks=self._allow_symlinks
116118
)
117-
if path.is_file() and not serialization.should_ignore(
118-
path, ignore_paths
119-
):
119+
if path.is_file():
120120
paths.append(path)
121121

122122
manifest_items = []

src/model_signing/_serialization/file_shard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ def serialize(
145145
(model_path,), model_path.glob("**/*")
146146
)
147147
for path in files_to_hash:
148+
if serialization.should_ignore(path, ignore_paths):
149+
continue
148150
serialization.check_file_or_directory(
149151
path, allow_symlinks=self._allow_symlinks
150152
)
151-
if path.is_file() and not serialization.should_ignore(
152-
path, ignore_paths
153-
):
153+
if path.is_file():
154154
shards.extend(self._get_shards(path))
155155

156156
manifest_items = []

tests/_serialization/file_shard_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,9 @@ def test_ignore_list_respects_directories(self, sample_model_folder):
387387
)
388388
assert manifest1 != manifest2
389389
assert len(manifest1._item_to_digest) > len(manifest2._item_to_digest)
390+
391+
def test_ignored_symlinks_dont_raise_error(self, symlink_model_folder):
392+
serializer = file_shard.Serializer(self._hasher_factory)
393+
_ = serializer.serialize(
394+
symlink_model_folder, ignore_paths=[symlink_model_folder]
395+
)

tests/_serialization/file_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ def test_ignore_list_respects_directories(self, sample_model_folder):
320320
diff = len(manifest1._item_to_digest) - len(manifest2._item_to_digest)
321321
assert diff == ignored_file_count
322322

323+
def test_ignored_symlinks_dont_raise_error(self, symlink_model_folder):
324+
serializer = file.Serializer(self._hasher_factory)
325+
_ = serializer.serialize(
326+
symlink_model_folder, ignore_paths=[symlink_model_folder]
327+
)
328+
323329

324330
class TestUtilities:
325331
def test_check_file_or_directory_raises_on_pipes(self, sample_model_file):

0 commit comments

Comments
 (0)