Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-09-20 10:21:11 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-09-20 10:21:11 (GMT)
commitdce9c18d56db8c9d07f08526aaca36789eda816b (patch)
treeaece65eecb4114e41a7255da4665e9d60176a923
parent63fd57e7f7f71d43b4e6d9ceb4000fce5007d51b (diff)
Add a suggested_filename property which the journal
can use to suggest a filename when copying on an USB stick. Using the filelike is not good because it would require a file copy. And the filename property conflicts with the import code. Maybe we can figure out a better way to do it after trial-3. This is all internal so it shouldn't cause any format compatibility issue.
-rw-r--r--NEWS2
-rw-r--r--src/olpc/datastore/backingstore.py29
2 files changed, 29 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index eed9446..09766c3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+* #3469 Human readable names on USB. (marco)
+
Snapshot 11013dc3ca
* #3599 Fix the import logic on USB sticks. (marco)
diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py
index bf0c94d..dc6b2ef 100644
--- a/src/olpc/datastore/backingstore.py
+++ b/src/olpc/datastore/backingstore.py
@@ -640,8 +640,6 @@ class InplaceFileBackingStore(FileBackingStore):
# blacklist all the hidden directories
if '/.' in dirpath: continue
- logging.info([ dirpath, dirname, filenames ])
-
for fn in filenames:
# give the thread a chance to exit
if not self._runWalker: break
@@ -713,6 +711,29 @@ class InplaceFileBackingStore(FileBackingStore):
except Exception, exc:
completion(exc)
+ def _get_unique_filename(self, suggested_filename):
+ filename = suggested_filename.replace('/', '_')
+
+ # FAT limit is 255, leave some space for uniqueness
+ max_len = 250
+ if len(filename) > max_len:
+ name, extension = os.path.splitext(filename)
+ filename = name[0:max_len - extension] + extension
+
+ if os.path.exists(os.path.join(self.uri, filename)):
+ i = 1
+ while len(filename) <= max_len:
+ name, extension = os.path.splitext(filename)
+ filename = name + '_' + str(i) + extension
+ if not os.path.exists(os.path.join(self.uri, filename)):
+ break
+ i += 1
+
+ if len(filename) > max_len:
+ filename = None
+
+ return filename
+
def create(self, props, filelike, can_move=False):
# the file would have already been changed inplace
# don't touch it
@@ -728,6 +749,10 @@ class InplaceFileBackingStore(FileBackingStore):
# 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:
proposed_name = os.path.split(filelike.name)[1]
# record the name before qualifying it to the store
props['filename'] = proposed_name