def make_valid_filename(customerIDURL, glob_path): """ Must be a customer, and then we make full path filename for where this packet is stored locally. """ keyAlias = glob_path['key_alias'] or 'master' packetID = glob_path['path'] customerGlobID = glob_path['customer'] if not customerGlobID: lg.warn("customer id is empty") return '' if not packetid.Valid(packetID): # SECURITY if packetID not in [ settings.BackupInfoFileName(), settings.BackupInfoFileNameOld(), settings.BackupInfoEncryptedFileName(), settings.BackupIndexFileName() ]: lg.warn('invalid file path') return '' if not contactsdb.is_customer(customerIDURL): # SECURITY lg.warn("%s is not my customer" % (customerIDURL)) if customerGlobID: if glob_path['idurl'] != customerIDURL: lg.warn('making filename for another customer: %s != %s' % (glob_path['idurl'], customerIDURL)) filename = make_filename(customerGlobID, packetID, keyAlias) return filename
def QueueRequestFile(self, callOnReceived, creatorID, packetID, ownerID, remoteID): # make sure that we don't actually already have the file # if packetID != settings.BackupInfoFileName(): remoteID = id_url.field(remoteID) ownerID = id_url.field(ownerID) creatorID = id_url.field(creatorID) if packetID not in [ settings.BackupInfoFileName(), settings.BackupInfoFileNameOld(), settings.BackupInfoEncryptedFileName(), ]: customer, pathID = packetid.SplitPacketID(packetID) filename = os.path.join(settings.getLocalBackupsDir(), customer, pathID) if os.path.exists(filename): lg.warn("%s already exist " % filename) if callOnReceived: reactor.callLater(0, callOnReceived, packetID, 'exist') # @UndefinedVariable return False if remoteID not in list(self.supplierQueues.keys()): # made a new queue for this man self.supplierQueues[remoteID] = SupplierQueue( remoteID, self.creatorID) lg.info("made a new receiving queue for %s" % nameurl.GetName(remoteID)) # lg.out(10, "io_throttle.QueueRequestFile asking for %s from %s" % (packetID, nameurl.GetName(remoteID))) return self.supplierQueues[remoteID].SupplierRequestFile( callOnReceived, creatorID, packetID, ownerID)
def makeFilename(customerIDURL, packetID): """ Must be a customer, and then we make full path filename for where this packet is stored locally. """ customerGlobID, packetID = packetid.SplitPacketID(packetID) if not packetid.Valid(packetID): # SECURITY if packetID not in [ settings.BackupInfoFileName(), settings.BackupInfoFileNameOld(), settings.BackupInfoEncryptedFileName(), settings.BackupIndexFileName() ]: # lg.out(1, "p2p_service.makeFilename ERROR failed packetID format: " + packetID ) return '' if not contactsdb.is_customer(customerIDURL): # SECURITY lg.warn("%s is not a customer" % (customerIDURL)) return '' if customerGlobID: customerIDURL_packet = global_id.GlobalUserToIDURL(customerGlobID) if customerIDURL_packet != customerIDURL: lg.warn('making filename for another customer: %s != %s' % (customerIDURL_packet, customerIDURL)) return constructFilename(customerIDURL, packetID)