commit f90e3c0d418e0fd618ef8a511a2864581e8f6cde
parent e4c665be6e24726051bfa0c784cef5a8b05b536c
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Sun, 4 Sep 2011 22:52:54 +0200
Improper symlink handling in updatehash.py .
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git 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