From f90e3c0d418e0fd618ef8a511a2864581e8f6cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Sun, 4 Sep 2011 22:52:54 +0200 Subject: [PATCH] Improper symlink handling in updatehash.py . --- updatehash.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/updatehash.py b/updatehash.py index 7f5b855..d437c4b 100755 --- a/updatehash.py +++ b/updatehash.py @@ -5,6 +5,7 @@ import os import sqlite3 import time import sys +import stat def checksumFile(path): md5 = hashlib.md5() @@ -18,8 +19,10 @@ def checksumFile(path): sha1.update(chunk) def fileInfo(path): - stat = os.stat(path) - return {'mtime':stat.st_mtime, 'size':stat.st_size} + st = os.lstat(path) + if not stat.S_ISREG(st.st_mode): + return None + return {'mtime':st.st_mtime, 'size':st.st_size} def initdb(cursor): cursor.execute("create table if not exists files(tag,timestamp,path primary key,md5,sha1,mtime,size)") @@ -41,6 +44,9 @@ def update(connection,cursor,path): fpath = os.path.join(dirpath, f) if os.path.isfile(fpath): fi = fileInfo(fpath) + if fi is None: + print "!skipping", fpath + continue cfi = cacheFileInfo(cursor,fpath) if fi != cfi: print " updating", fpath