################################################################################
+import apt_pkg
import os
from os.path import normpath
import re
# in the database
from config import Config
from textutils import fix_maintainer
-from dak_exceptions import DBUpdateError, NoSourceFieldError
+from dak_exceptions import DBUpdateError, NoSourceFieldError, FileExistsError
# suppress some deprecation warnings in squeeze related to sqlalchemy
import warnings
else:
os.symlink(targetpath, queuepath)
qf.fileid = poolfile.file_id
+ except FileExistsError:
+ if not poolfile.identical_to(queuepath):
+ raise
except OSError:
return None
# Always copy files from policy queues as they might move around.
import utils
utils.copy(source, target)
+ except FileExistsError:
+ if not policyqueuefile.identical_to(target):
+ raise
except OSError:
return None
def __repr__(self):
return '<ChangePendingFile %s>' % self.change_pending_file_id
+ def identical_to(self, filename):
+ """
+ compare size and hash with the given file
+
+ @rtype: bool
+ @return: true if the given file has the same size and hash as this object; false otherwise
+ """
+ st = os.stat(filename)
+ if self.size != st.st_size:
+ return False
+
+ f = open(filename, "r")
+ sha256sum = apt_pkg.sha256sum(f)
+ if sha256sum != self.sha256sum:
+ return False
+
+ return True
+
__all__.append('ChangePendingFile')
################################################################################
def not_null_constraints(self):
return ['filename', 'md5sum', 'location']
+ def identical_to(self, filename):
+ """
+ compare size and hash with the given file
+
+ @rtype: bool
+ @return: true if the given file has the same size and hash as this object; false otherwise
+ """
+ st = os.stat(filename)
+ if self.filesize != st.st_size:
+ return False
+
+ f = open(filename, "r")
+ sha256sum = apt_pkg.sha256sum(f)
+ if sha256sum != self.sha256sum:
+ return False
+
+ return True
+
__all__.append('PoolFile')
@session_wrapper