def getFsObjFromFullPath(self, fullPath): ''' Return object info with {"ufsUrl": "ufs://hostname/D:/tmp/xxx", "size": size, "timestamp": timestamp} ''' objInFs = ufsObj.fsObj(fullPath) if objInFs.isContainer(): res = self.getFsContainerObjFromFullPath(fullPath) ncl("returning: ", res["uuid"]) return res ufsUrl = objInFs.getObjUfsUrl() if not objInFs.exists(): ncl(fullPath) raise ObjectDoesNotExistInLocalFileSystem() return None for i in self.objDb.find({"ufsUrl": ufsUrl}).sort("timestamp", -1): #Check if the item is updated if objInFs["size"] == i["size"]: #Object size NOT changed if objInFs["timestamp"] == i["timestamp"]: #Object size and time NOT changed, treated it as NOT changed. del i["_id"] ncl(i) return ufsObj.ufsUrlObj(ufsUrl, i) if objInFs["headMd5"] == i["headMd5"]: #The file is changed, but the content is not changed. Update the timestamp for the obj or add new item with new timestamp? ncl('existing item as size and hash is the same, return existing info') #Update the timestamp in the database as the item's timestamp in file system is different self.objDb.find_and_modify({"uuid":i["uuid"]}, {"$set": {"timestamp":objInFs["timestamp"]}}) ncl("returnning: ", i["uuid"]) del i["_id"] ncl(i) return ufsObj.ufsUrlObj(ufsUrl, i) #The item is updated add the new item latestInfo = objInFs.getItemInfo() #objInFs["uuid"] = unicode(str(uuid.uuid4())) #objInFs["user"] = self.user objInFs["ufsUrl"] = ufsUrl #self.objDb.insert(objInFs.getItemInfo(), safe=True) #ncl('returning new obj') #print objInFs["uuid"] return self.insertObj(objInFs)
def getFsContainerObjFromFullPath(self, fullPath): dirObjInFs = ufsObj.fsDirObj(fullPath) ufsUrl = dirObjInFs.getObjUfsUrl() if not dirObjInFs.exists(): cl('obj does not exists', fullPath) raise ObjectDoesNotExistInLocalFileSystem() return None #cl('finding url:', ufsUrl) for i in self.objDb.find({"ufsUrl": ufsUrl}).sort("timestamp", -1): #Check if the item is updated if dirObjInFs["timestamp"] == i["timestamp"]: #Object time NOT changed, treated it as NOT changed. #cl("item not changed:", i) return ufsObj.ufsUrlObj(ufsUrl, i) #The item is updated add the new item latestInfo = dirObjInFs.getItemInfo() #dirObjInFs["uuid"] = unicode(str(uuid.uuid4())) #dirObjInFs["user"] = self.user dirObjInFs["ufsUrl"] = ufsUrl #dirObjInFs["addedTimestamp"] = time.time() #self.objDb.insert(dirObjInFs.getItemInfo(), safe=True) #ncl('returning new obj') #print objInFs["uuid"] return self.insertObj(dirObjInFs)
def getFsObjFromUfsUrl(self, ufsUrl): ufsUrlObj = ufsObj.ufsUrlObj(ufsUrl) return self.getFsObjFromFullPath(ufsUrlObj["fullPath"])
def getFullPathFromUfsUrl(self, ufsUrl): ufsUrlObj = ufsObj.ufsUrlObj(ufsUrl) return ufsUrlObj["fullPath"]