[xiph-cvs] cvs commit: positron/positron add_file.py neuros.py
Stan Seibert
volsung at xiph.org
Sat May 24 12:29:09 PDT 2003
volsung 03/05/24 15:29:09
Modified: positron add_file.py neuros.py
Log:
Mangle filenames with characters that are illegal in the FAT filesystem.
Fixes bug #349.
Revision Changes Path
1.2 +2 -2 positron/positron/add_file.py
Index: add_file.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/add_file.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- add_file.py 22 May 2003 04:42:52 -0000 1.1
+++ add_file.py 24 May 2003 19:29:09 -0000 1.2
@@ -45,8 +45,8 @@
# Don't need to copy files already on the Neuros
filelist.append((None, fullname))
else:
- targetname = path.join(target_prefix, name)
-
+ targetname = neuros.mangle_hostpath(path.join(target_prefix,
+ name))
if path.exists(targetname):
if not silent:
print "Skipping %s because %s already exists." \
<p><p>1.2 +35 -0 positron/positron/neuros.py
Index: neuros.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/neuros.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- neuros.py 22 May 2003 04:42:52 -0000 1.1
+++ neuros.py 24 May 2003 19:29:09 -0000 1.2
@@ -39,6 +39,30 @@
return path_parts
+def FAT_mangle_filename(filename):
+ """Creates a FAT-friendly filename.
+
+ Substitute replacement characters (usually '_') for characters in
+ filename that are not allowed on FAT filesystems. Double quotes are
+ replaced with single quotes."""
+
+ # Keys are bad characters for FAT filesystems, and values are the
+ # replacement
+ mangle_table = { '\\' : '_',
+ ':' : '_',
+ '*' : '_',
+ '?' : '_',
+ '"' : "'",
+ '<' : '_',
+ '>' : '_',
+ '|' : '_' }
+
+ new_filename = filename
+ for bad_char, replace_char in mangle_table.items():
+ new_filename = new_filename.replace(bad_char, replace_char)
+
+ return new_filename
+
class Neuros:
DB_DIR = path.normcase("WOID_DB")
@@ -169,5 +193,16 @@
raise Error("Neuros path does not start with C:")
hostpath_parts = self.mountpoint_parts + neurospath_parts[1:]
+
+ return path.join(*hostpath_parts)
+
+ def mangle_hostpath(self, hostpath):
+ if not self.is_valid_hostpath(hostpath):
+ raise Error("Host path not under Neuros mountpoint")
+
+ # Only mangle the parts after the mountpoint
+ hostpath_parts = _total_path_split(hostpath)[len(self.mountpoint_parts):]
+ hostpath_parts = self.mountpoint_parts + \
+ map(FAT_mangle_filename, hostpath_parts)
return path.join(*hostpath_parts)
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list