All pastes #994725 Raw Edit

Untitled

public text v1 · immutable
#994725 ·published 2008-04-23 16:47 UTC
rendered paste body
##On FileTransfer.py


        # separated folders between contacts
        if config.user['receivedFilesSortedByUser']:
            receivedFilesDirSub = os.path.join(receivedFilesDir, p2p.mail)
            
            if os.path.exists(receivedFilesDirSub):
                receivedFilesDir = receivedFilesDirSub
            else:
                os.mkdir(receivedFilesDirSub)
                # ugly, but "if os.mkdir(..)" doesn't work :S
                if os.path.exists(receivedFilesDirSub):
                    receivedFilesDir = receivedFilesDirSub
                    # if we can't create the dir, we put the file directly 
                    # in received files dir
        
        #os.path.join(receivedFilesDir, self.getFilename())
        path = receivedFilesDir+'/'
        
        num = 0
        increaseIt = self.getFilename()
        
        while os.path.exists(path + increaseIt):
            num += 1
            myFile = self.getFilename()
            myLen = len(myFile)
            lastDot = myFile.rfind(".")
            lastChar = myLen-lastDot#12-9
            second = myFile[lastDot:]
            first = myFile[:-lastChar]
            increaseIt=first+str(num)+second
			
			
        self.localPath = path + increaseIt
        
        # we don't copy because the permissions may be too restrictive
        # and not match the user preferred umask blah blah
        dest = open(self.localPath, 'wb')
        src.seek(0)
        buffer = src.read(32 * 1024)
        while buffer:
            dest.write(buffer)
            buffer = src.read(32 * 1024)
        dest.close()
        src.close()