Skip to content

Commit 64e8ea7

Browse files
committed
Improve handling of systems with improperly configured file system encoding
Closes #289
1 parent ed9475d commit 64e8ea7

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Version 0.16
77
------------
88

99
(bugfix release, released on X)
10+
- Improve handling of systems with improperly configured file system encoding (#289)
1011
- Fix "All archives" output for attic info. (#183)
1112
- More user friendly error message when repository key file is not found (#236)
1213
- Fix parsing of iso 8601 timestamps with zero microseconds (#282)

attic/archive.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class DoesNotExist(Error):
119119
class AlreadyExists(Error):
120120
"""Archive {} already exists"""
121121

122+
class IncompatibleFilesystemEncodingError(Error):
123+
"""Failed to encode filename "{}" into file system encoding "{}". Consider configuring the LANG environment variable."""
124+
125+
122126
def __init__(self, repository, key, manifest, name, cache=None, create=False,
123127
checkpoint_interval=300, numeric_owner=False):
124128
self.cwd = os.getcwd()
@@ -247,6 +251,8 @@ def extract_item(self, item, restore_attrs=True, dry_run=False):
247251
os.rmdir(path)
248252
else:
249253
os.unlink(path)
254+
except UnicodeEncodeError:
255+
raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding())
250256
except OSError:
251257
pass
252258
mode = item[b'mode']

attic/archiver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ def _process(self, archive, cache, excludes, exclude_caches, skip_inodes, path,
188188
def do_extract(self, args):
189189
"""Extract archive contents"""
190190
# be restrictive when restoring files, restore permissions later
191+
if sys.getfilesystemencoding() == 'ascii':
192+
print('Warning: File system encoding is "ascii", extracting non-ascii filenames will not be supported.')
191193
os.umask(0o077)
192194
repository = self.open_repository(args.archive)
193195
manifest, key = Manifest.load(repository)

0 commit comments

Comments
 (0)