aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/xattr_user_crc3220
1 files changed, 11 insertions, 9 deletions
diff --git a/scripts/xattr_user_crc32 b/scripts/xattr_user_crc32
index a13840f..8f47bdd 100755
--- a/scripts/xattr_user_crc32
+++ b/scripts/xattr_user_crc32
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright 2020 vg
+# Copyright 2022 vg
# SPDX-License-Identifier: MIT
'''
@@ -24,15 +24,15 @@ Options:
Null instead of LF as filename separator for in and out
'''
-### standard modules
+# standard modules
import contextlib
import functools
import itertools
-import operator
-import os
import sys
+from os import getxattr, setxattr
+from os.path import basename
-### external modules
+# external modules
import docopt
@@ -69,16 +69,18 @@ def get_crc32(filename):
def main():
- args = docopt.docopt(__doc__.format(progname=os.path.basename(sys.argv[0])))
+ args = docopt.docopt(__doc__.format(progname=basename(sys.argv[0])))
separator = '\0' if args['-z'] else '\n'
for filename in filenames(args['FILENAME'], separator):
tag_crc32 = None
with contextlib.suppress(OSError):
- tag_crc32 = os.getxattr(filename, 'user.crc32').decode('utf8')
+ tag_crc32 = getxattr(filename, 'user.crc32').decode('utf8')
calculated_crc32 = get_crc32(filename)
- os.setxattr(filename, 'user.crc32', calculated_crc32.encode('utf8'))
+ if tag_crc32 != calculated_crc32:
+ # write access to filesystem only if needed
+ setxattr(filename, 'user.crc32', calculated_crc32.encode('utf8'))
print('%-8s %-8s %s'
- % (tag_crc32, calculated_crc32, filename), end=separator)
+ % (tag_crc32, calculated_crc32, filename), end=separator)
main()