Exemple #1
0
 def lineReceived(self, line):
     name = line.strip()
     if name in self.factory.allowedList:
         f = self.factory.allowedList[name][0]
         df = self.factory.allowedList[name][1]
         # print "Sending " + name
         buf = f.read()
         self.transport.write(buf)
         f.close()
         df.callback("Closed")
         del self.factory.allowedList[name]
     else:
         try:
             # Sanitize input:
             name = os.path.join(self.factory.dirname,os.path.basename(name))
             # This is bad: for example, try sending "/etc/passwd" to the server
             #path = os.path.join(self.factory.dirname,name)
             f = ChunkFile(name)
             print "Sending " + name
             buf = f.read()
             self.transport.write(buf)
             f.close()
         except IOError:
             print "File " + name + " not found"
     self.transport.loseConnection()
Exemple #2
0
 def lineReceived(self, line):
     name = line.strip()
     if name in self.factory.allowedList:
         f = self.factory.allowedList[name][0]
         df = self.factory.allowedList[name][1]
         # print "Sending " + name
         buf = f.read()
         self.transport.write(buf)
         f.close()
         df.callback("Closed")
         del self.factory.allowedList[name]
     else:
         try:
             # Sanitize input:
             name = os.path.join(self.factory.dirname,
                                 os.path.basename(name))
             # This is bad: for example, try sending "/etc/passwd" to the server
             #path = os.path.join(self.factory.dirname,name)
             f = ChunkFile(name)
             print "Sending " + name
             buf = f.read()
             self.transport.write(buf)
             f.close()
         except IOError:
             print "File " + name + " not found"
     self.transport.loseConnection()
Exemple #3
0
class Chunk:
    # initialize the chunk with the name of the dir getting backed up
    def __init__(self, dirname, realbase, virtbase):
        self.realdir = os.path.join(realbase,dirname)
        self.virtdir = os.path.join(virtbase,dirname).rstrip(os.path.sep)
        self.name = hashlib.sha1(self.virtdir).hexdigest() + ".tar.bz2"

    # Make an archive of the files in this chunk
    def archive(self,storageDir):
        self.fileName = os.path.join(storageDir,self.name)
        tar = tarfile.open(self.fileName, 'w:bz2')
        files = os.listdir(self.realdir)
        #print files
        for fname in files:
            path = os.path.join(self.realdir,fname)
            if(os.path.isdir(path)):
                tar.add(path,fname,recursive = False)
                #continue
            else:
                #print "archive: " + fname
                tar.add(path,fname)
        tar.close()
        self.chunkfile = ChunkFile(self.fileName)
        return self.chunkfile

    # Delete this chunk's tar file
    def dissolve(self,result):
        self.chunkfile.close()
        # print "dissolving " + self.name
        os.remove(self.fileName)
Exemple #4
0
class Chunk:
    # initialize the chunk with the name of the dir getting backed up
    def __init__(self, dirname, realbase, virtbase):
        self.realdir = os.path.join(realbase, dirname)
        self.virtdir = os.path.join(virtbase, dirname).rstrip(os.path.sep)
        self.name = hashlib.sha1(self.virtdir).hexdigest() + ".tar.bz2"

    # Make an archive of the files in this chunk
    def archive(self, storageDir):
        self.fileName = os.path.join(storageDir, self.name)
        tar = tarfile.open(self.fileName, 'w:bz2')
        files = os.listdir(self.realdir)
        #print files
        for fname in files:
            path = os.path.join(self.realdir, fname)
            if (os.path.isdir(path)):
                tar.add(path, fname, recursive=False)
                #continue
            else:
                #print "archive: " + fname
                tar.add(path, fname)
        tar.close()
        self.chunkfile = ChunkFile(self.fileName)
        return self.chunkfile

    # Delete this chunk's tar file
    def dissolve(self, result):
        self.chunkfile.close()
        # print "dissolving " + self.name
        os.remove(self.fileName)
Exemple #5
0
 def archive(self, storageDir):
     self.fileName = os.path.join(storageDir, self.name)
     tar = tarfile.open(self.fileName, 'w:bz2')
     files = os.listdir(self.realdir)
     #print files
     for fname in files:
         path = os.path.join(self.realdir, fname)
         if (os.path.isdir(path)):
             tar.add(path, fname, recursive=False)
             #continue
         else:
             #print "archive: " + fname
             tar.add(path, fname)
     tar.close()
     self.chunkfile = ChunkFile(self.fileName)
     return self.chunkfile
Exemple #6
0
 def archive(self,storageDir):
     self.fileName = os.path.join(storageDir,self.name)
     tar = tarfile.open(self.fileName, 'w:bz2')
     files = os.listdir(self.realdir)
     #print files
     for fname in files:
         path = os.path.join(self.realdir,fname)
         if(os.path.isdir(path)):
             tar.add(path,fname,recursive = False)
             #continue
         else:
             #print "archive: " + fname
             tar.add(path,fname)
     tar.close()
     self.chunkfile = ChunkFile(self.fileName)
     return self.chunkfile