Skip to content
Snippets Groups Projects
Commit 1f59635f authored by Wainer Vandelli's avatar Wainer Vandelli
Browse files

Move validity check into the file deletion method

parent a41babfd
No related branches found
No related tags found
No related merge requests found
...@@ -84,21 +84,34 @@ class DeleteThread(threading.Thread): ...@@ -84,21 +84,34 @@ class DeleteThread(threading.Thread):
# end def __init__() # end def __init__()
def delete(self, deletefile): def delete(self, deletefile):
file = deletefile[0]
filename = deletefile[0]
##### Delete file soon ##### pool = deletefile[1]
os.remove(file) stagehost = deletefile[3]
os.remove(file+copied_ext) copyDir = deletefile[2]
#Remote file name for validity check
castorfile = os.path.join(copyDir,
os.path.basename(filename))
success = self.checkvalidity(filename, castorfile, stagehost, pool)
if not success:
self.logger.warning('Remote file validity check failed. Not deleting local file %s' % filename)
return
##### Delete file #####
os.remove(filename)
os.remove(filename+copied_ext)
##### Update Oracle Metadata Database, if connection is fine ##### ##### Update Oracle Metadata Database, if connection is fine #####
##### File table: filestate from CLOSED to DELETED ##### ##### File table: filestate from CLOSED to DELETED #####
if self.db: if self.db:
self.logger.info('Update Metadata database') self.logger.info('Update Metadata database')
self.dbLock.acquire() self.dbLock.acquire()
self.dbFlag = self.db.Deletion(file) self.dbFlag = self.db.Deletion(filename)
self.dbLock.release() self.dbLock.release()
elif self.conf.connection: elif self.conf.connection:
self.logger.warning('No connection to Metadata database: database will not be updated for file %s' % file) self.logger.warning('No connection to Metadata database: database will not be updated for file %s' % filename)
# end if,else # end if,else
##### Put .data deleted file in the clear queue ##### ##### Put .data deleted file in the clear queue #####
...@@ -218,22 +231,11 @@ class DeleteThread(threading.Thread): ...@@ -218,22 +231,11 @@ class DeleteThread(threading.Thread):
continue continue
# end if # end if
# Remove file name for validity check
Castor_file = os.path.join(copyDir,
os.path.basename(filename))
##### Check if migration is required ##### ##### Check if migration is required #####
if not self.migFlag: if not self.migFlag:
self.logger.debug('Migration not required by the deletion policy: delete file ' + filename) self.logger.debug('Migration not required by the deletion policy: delete file ' + filename)
### Check sizes and checksum before deletion ### self.delete(deletefile)
success = self.checkvalidity(filename, Castor_file, stagehost, pool)
if success:
self.delete(deletefile)
else:
self.logger.warning('Remote file validity check failed. Not deleting local file %s' % filename)
continue continue
# end if # end if
...@@ -254,11 +256,7 @@ class DeleteThread(threading.Thread): ...@@ -254,11 +256,7 @@ class DeleteThread(threading.Thread):
self.logger.debug('File migrated: going to delete file ' self.logger.debug('File migrated: going to delete file '
+ filename) + filename)
success = self.checkvalidity(filename, Castor_file, stagehost, pool) self.delete(deletefile)
if success:
self.delete(deletefile)
else:
self.logger.warning('Remote file validity check failed. Not deleting local file %s' % filename)
del self.MigDict[filename] del self.MigDict[filename]
#block until room is available in the queue ????? #block until room is available in the queue ?????
...@@ -314,11 +312,14 @@ class DeleteThread(threading.Thread): ...@@ -314,11 +312,14 @@ class DeleteThread(threading.Thread):
success &= (dbchecksum.lower() == checksum.lower()) success &= (dbchecksum.lower() == checksum.lower())
elif dbchecksum: elif dbchecksum:
success &= (dbchecksum.lower() == checksum.lower()) success &= (dbchecksum.lower() == checksum.lower())
report = 'Validity for %s --> %s (Local size: %d - Remote size: %d - DB size: %d)(Expected checksum: %s - Remote checksum: %s)' % (sfofile, str(success), sfofilesize, castorfilesize, (dbfilesize if dbfilesize else -1),str(dbchecksum),str(checksum))
if not success: if not success:
self.logger.warning('Checksum check or size check failed for: %s (Local size: %d - Remote size: %d - DB size: %d)(Expected checksum: %s - Remote checksum: %s)' % (sfofile, sfofilesize, castorfilesize, (dbfilesize if dbfilesize else -1),str(dbchecksum),str(checksum))) self.logger.warning('Validity check failed! %s' % report)
self.logger.debug('Validity for %s --> %s (Local size: %d - Remote size: %d - DB size: %d)(Expected checksum: %s - Remote checksum: %s)' % (sfofile, str(success), sfofilesize, castorfilesize, (dbfilesize if dbfilesize else -1),str(dbchecksum),str(checksum))) self.logger.debug(report)
return success return success
......
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