Commit aeaedd01 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Handle file/dir names with illegal characters.

parent ea34e6e3
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,14 @@ class MultipleUsersException(Error):
        super(MultipleUsersException, self).__init__(self.message)
        super(MultipleUsersException, self).__init__(self.message)




# SystemUtils exceptions

class IllegalCharacterException(Error):
    def __init__(self, name):
        self.message = "Illegal character found in: " + name
        super(IllegalCharacterException, self).__init__(self.message)


# TapeClient exceptions
# TapeClient exceptions


class TapeClientException(Error):
class TapeClientException(Error):
+19 −3
Original line number Original line Diff line number Diff line
@@ -6,9 +6,12 @@
#
#


import os
import os
import re
import shutil
import shutil
import sys
import sys


from exceptions import IllegalCharacterException



class SystemUtils(object):
class SystemUtils(object):
    
    
@@ -45,17 +48,30 @@ class SystemUtils(object):
            fp.close()
            fp.close()
            return False
            return False


    def findIllegalCharacters(self, name):
        """Checks for file/dir names containing illegal characters."""
        pattern = re.compile(r"[<>?\":/|'*`\\]")
        if re.search(pattern, name):
            return True
        else:
            return False

    def scanRecursive(self, path):
    def scanRecursive(self, path):
        dirList = []
        dirList = []
        fileList = []
        fileList = []
        for folder, subfolders, files in os.walk(path, topdown = True):
        for folder, subfolders, files in os.walk(path, topdown = True):
            cwd = os.path.basename(folder)
            cwd = os.path.basename(folder)
            if folder != path:
            if folder != path:
                parent = os.path.dirname(folder)
                folderAbsPath = os.path.dirname(folder) + '/' + cwd
                dirList.append(parent + '/' + cwd)
                if self.findIllegalCharacters(cwd):
                    raise(IllegalCharacterException(folderAbsPath))
                dirList.append(folderAbsPath)
                i = 0
                i = 0
                for f in files:
                for f in files:
                    files[i] = parent + '/' + cwd + '/' + f
                    fileAbsPath = folderAbsPath + '/' + f
                    if self.findIllegalCharacters(f):
                        raise(IllegalCharacterException(fileAbsPath))
                    files[i] = fileAbsPath
                    i += 1
                    i += 1
                fileList.append(files)
                fileList.append(files)
        return [ dirList, fileList ]
        return [ dirList, fileList ]