Skip to content
Snippets Groups Projects
Commit b8cdfa88 authored by sveseli's avatar sveseli
Browse files

optimized detection of existing files

parent 56efec33
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import copy
from fileTransferPlugin import FileTransferPlugin from fileTransferPlugin import FileTransferPlugin
from dm.common.utility.fileUtility import FileUtility from dm.common.utility.fileUtility import FileUtility
from dm.common.utility.ftpUtility import FtpUtility from dm.common.utility.ftpUtility import FtpUtility
...@@ -48,27 +49,31 @@ class GridftpFileTransferPlugin(FileTransferPlugin): ...@@ -48,27 +49,31 @@ class GridftpFileTransferPlugin(FileTransferPlugin):
(scheme, host, port, replacementDirPath) = FtpUtility.parseFtpUrl(dataDirectory) (scheme, host, port, replacementDirPath) = FtpUtility.parseFtpUrl(dataDirectory)
ftpUtility = SftpUtility(storageHost) ftpUtility = SftpUtility(storageHost)
storageFilePathsDict = ftpUtility.getFiles(storageDirectory, {}, replacementDirPath) storageFilePathsDict = ftpUtility.getFiles(storageDirectory, {}, replacementDirPath)
pluginFilePathsDict = {} pluginFilePathsDict = copy.copy(filePathsDict)
filePaths = filePathsDict.keys() # Remove file from plugin dict if we do not need to transfer it
for filePath in filePaths: for (filePath,storageFilePathDict) in storageFilePathsDict.items():
filePathDict = filePathsDict.get(filePath) filePathDict = filePathsDict.get(filePath)
storageFilePathDict = storageFilePathsDict.get(filePath) if filePathDict is None:
# We are not attempting to transfer this file
if not storageFilePathDict: # No need to change plugin file dict
# remote directory does not have the file continue
pluginFilePathsDict[filePath] = filePathDict
else: # Check size
fSize = filePathDict.get('fileSize') fSize = filePathDict.get('fileSize')
sfSize = storageFilePathDict.get('fileSize') sfSize = storageFilePathDict.get('fileSize')
# check size if not fSize or not sfSize or fSize != sfSize:
if not fSize or not sfSize or fSize != sfSize: # Sizes differ, need to transfer file
pluginFilePathsDict[filePath] = filePathDict continue
else:
# sizes are the same, check modify time # Sizes are the same, check modify time
mTime = filePathDict.get('fileModificationTime') mTime = filePathDict.get('fileModificationTime')
smTime = storageFilePathDict.get('fileModificationTime') smTime = storageFilePathDict.get('fileModificationTime')
if not mTime or not smTime or mTime > smTime: if not mTime or not smTime or mTime > smTime:
pluginFilePathsDict[filePath] = filePathDict # Source time is later than storage time, need to transfer file
continue
# No need to transfer file
del pluginFilePathsDict[filePath]
self.logger.debug('Number of original files: %s, number of plugin files: %s', len(filePathsDict), len(pluginFilePathsDict)) self.logger.debug('Number of original files: %s, number of plugin files: %s', len(filePathsDict), len(pluginFilePathsDict))
return pluginFilePathsDict return pluginFilePathsDict
......
...@@ -143,3 +143,6 @@ if __name__ == '__main__': ...@@ -143,3 +143,6 @@ if __name__ == '__main__':
print files print files
print ftpUtility.getMd5Sum('/export/8-id-i/test/testfile01') print ftpUtility.getMd5Sum('/export/8-id-i/test/testfile01')
print ftpUtility.statFile('/export/8-id-i/test/testfile01') print ftpUtility.statFile('/export/8-id-i/test/testfile01')
#ftpUtility = FtpUtility('xstor-devel', 22)
#files = ftpUtility.getFiles('/data/testing')
#print files
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment