Add option --fs-fix=<auto|force|no>

Currently, the filesystem fixes are applied only for FAT, in which these
special characters (:, ", etc.) are actually forbidden. NTFS, however, will
allow you to create file names containing these characters, but Windows will
still be unable to deal with the files (even to rename them!).

--fs-fix=force will be useful when copying to a NTFS filesystem that will be
read on Windows.

--fs-fix=no is the same as --no-fs-fix.

--fs-fix=auto is the same as the current default behaviour (i.e. fix names only
for FAT).
This commit is contained in:
Matteo Cypriani 2018-04-15 12:32:39 +02:00
parent 20baa5ecd9
commit bf7e090fbf
1 changed files with 17 additions and 4 deletions

View File

@ -73,6 +73,7 @@ const_DBUS_INTERFACE = "org.goffi.gcp"
const_DBUS_PATH = "/org/goffi/gcp"
const_BUFF_SIZE = 4096
const_PRESERVE = set(['mode','ownership','timestamps'])
const_FS_FIX = set(['auto','force','no'])
const_FILES_DIR = "~/.gcp"
const_JOURNAL_PATH = const_FILES_DIR + "/journal"
const_SAVED_LIST = const_FILES_DIR + "/saved_list"
@ -411,7 +412,7 @@ class GCP():
@return: fixed filename"""
fixed_filename = filename
if self.getFsType(filename) == 'vfat' and options.fs_fix:
if options.fs_fix == 'force' or (options.fs_fix == 'auto' and self.getFsType(filename) == 'vfat'):
fixed_filename = filename.replace('\\','_')\
@ -573,8 +574,11 @@ class GCP():
#parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors")) #TODO
parser.add_option("--no-fs-fix", action="store_false", dest='fs_fix', default=True,
help=_("don't fix filesystem name incompatibily"))
parser.add_option("--fs-fix", action="store", dest='fs_fix', default='auto',
help=_("fix filesystem name incompatibily; can be 'auto' (default), 'force' or 'no'"))
parser.add_option("--no-fs-fix", action="store_true", dest='no_fs_fix', default=False,
help=_("same as --fs-fix=no (overrides --fs-fix)"))
parser.add_option("--no-progress", action="store_false", dest="progress", default=True,
help=_("deactivate progress bar"))
@ -617,9 +621,18 @@ class GCP():
if options.verbose:
if options.no_fs_fix:
options.fs_fix = 'no'
if not options.fs_fix in const_FS_FIX:
error (_("Invalid --fs-fix value\nvalid values are:"))
for value in const_FS_FIX:
error('- %s' % value)
preserve = set(options.preserve.split(','))
if not preserve.issubset(const_PRESERVE):
error (_("Invalide --preserve value\nvalid values are:"))
error (_("Invalid --preserve value\nvalid values are:"))
for value in const_PRESERVE:
error('- %s' % value)