#4784 HIGH Update.: Journal items with invalid names don't transfer to usb sticks
Zarro Boogs per Child
bugtracker at laptop.org
Mon Nov 12 05:44:18 EST 2007
#4784: Journal items with invalid names don't transfer to usb sticks
-------------------------------+--------------------------------------------
Reporter: AlexL | Owner: tomeu
Type: defect | Status: new
Priority: high | Milestone: Update.1
Component: journal-activity | Version:
Resolution: | Keywords:
Verified: 0 |
-------------------------------+--------------------------------------------
Comment(by tomeu):
The following patch should remove the invalid FAT characters from the file
name.
{{{
diff --git a/src/olpc/datastore/backingstore.py
b/src/olpc/datastore/backingstore.py
index 9021448..6e307ee 100644
--- a/src/olpc/datastore/backingstore.py
+++ b/src/olpc/datastore/backingstore.py
@@ -787,9 +787,13 @@ class InplaceFileBackingStore(FileBackingStore):
completion(exc)
def _get_unique_filename(self, suggested_filename):
- filename = suggested_filename.replace('/', '_')
- filename = filename.replace(':', '_')
- filename = filename.replace('\n', '_')
+ # Invalid characters in VFAT filenames. From
+ # http://en.wikipedia.org/wiki/File_Allocation_Table
+ invalid_chars = ['/', '\\', ':', '*', '?', '"', '<', '>', '|',
'\x7F']
+ invalid_chars.extend([chr(x) for x in range(0, 32)])
+ filename = suggested_filename
+ for char in invalid_chars:
+ filename = filename.replace(char, '_')
# FAT limit is 255, leave some space for uniqueness
max_len = 250
@@ -825,12 +829,14 @@ class InplaceFileBackingStore(FileBackingStore):
# files to these devices we need to detect this case and
# place the file
proposed_name = props.get('filename', None)
- if not proposed_name:
- suggested = props.get('suggested_filename', None)
- if suggested:
- proposed_name = self._get_unique_filename(suggested)
- if not proposed_name:
+ if proposed_name is None:
+ proposed_name = props.get('suggested_filename', None)
+
+ if proposed_name is not None:
+ proposed_name = self._get_unique_filename(proposed_name)
+ else:
proposed_name = os.path.split(filelike.name)[1]
+
# record the name before qualifying it to the store
props['filename'] = proposed_name
proposed_name = os.path.join(self.uri, proposed_name)
}}}
About falling back to some simple file name when the copy fails, I'm a
little worried about this because the copy itself is done conditionally
async, so we would have to alter the code in a non-simple way.
Marco suggested trying to create the file with open() and, on error, fall
back to a simpler file name.
--
Ticket URL: <http://dev.laptop.org/ticket/4784#comment:3>
One Laptop Per Child <http://dev.laptop.org>
OLPC bug tracking system
More information about the Bugs
mailing list