Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check whether xattr is changed before and after clear #57

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 18 additions & 2 deletions src/exif_stripper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@
else:
# remove extended attributes (Unix only)
if platform.system() != 'Windows':
import warnings

from xattr import xattr

xattr_obj = xattr(filename)
if xattr_obj.list():
xattr_list = xattr_obj.list()

if xattr_list:
original_xattr_list = xattr_list[:]

xattr_obj.clear()
has_changed = True

xattr_obj = xattr(filename)
xattr_list = xattr_obj.list()

has_changed |= set(xattr_list) != set(original_xattr_list)
if xattr_list:
xattr_list_str = ', '.join(xattr_list)
warnings.warn(

Check warning on line 58 in src/exif_stripper/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/exif_stripper/__init__.py#L57-L58

Added lines #L57 - L58 were not covered by tests
Lee-W marked this conversation as resolved.
Show resolved Hide resolved
f'Extended attributes {xattr_list_str} in {filename} cannot be removed.',
stacklevel=2,
)

if has_changed:
print(f'Stripped metadata from {filename}')
Expand Down
12 changes: 11 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

RUNNING_ON = platform.system()
RUNNING_ON_WINDOWS = RUNNING_ON == 'Windows'
RUNNING_ON_MACOS = RUNNING_ON == 'Darwin'
Lee-W marked this conversation as resolved.
Show resolved Hide resolved

if not RUNNING_ON_WINDOWS:
from xattr import xattr
Expand Down Expand Up @@ -51,7 +52,16 @@ def has_metadata(filepath, on_windows):
has_exif = dict(im.getexif()) != {}
if on_windows:
return has_exif
return has_exif or xattr(filepath).list()

xattr_list = xattr(filepath).list()
if RUNNING_ON_MACOS:
has_removable_xattr = any(
not attr.startswith('com.apple.') for attr in xattr_list
)
else:
has_removable_xattr = bool(xattr_list)

return has_exif or has_removable_xattr


def assert_metadata_stripped(filepath, on_windows=RUNNING_ON_WINDOWS):
Expand Down
Loading