diff --git a/file_list.py b/file_list.py index 6d76405..2117085 100755 --- a/file_list.py +++ b/file_list.py @@ -57,19 +57,18 @@ def createdb(fname): def delete_nonexisting(sqlfile,options): conn=sqlite3.connect(sqlfile) conn.text_factory=str - #conn.row_factory=sqlite3.Row db=conn.cursor() dbdel=conn.cursor() db.execute('SELECT file FROM list') for row in db: if os.path.exists(row[0]): - delete=False + delete=False if not options.symlinks: if os.path.islink(row[0]): - delete=True + delete=True else: delete=True - if delete: + if delete: print('removing.. '+row[0]) dbdel.execute("DELETE FROM list where file == ?",(row[0],)) conn.commit() @@ -81,13 +80,15 @@ def add_recurse(options): db=conn.cursor() for path,dirs,files in os.walk(options.startpath,followlinks=options.symlinks): dirs=clean_dirs(dirs) + db_files=get_folder_contents(db,os.path.abspath(path)+'/') if not options.symlinks: files=clean_syms(files,path) for file in files: filename=os.path.abspath(os.path.join(path,file)) if file==options.sqlfile: continue - if not is_listed(db,filename): + #if not is_listed(db,filename): + if file not in db_files: if options.add: add_single(conn,filename,change=False) else: @@ -96,7 +97,7 @@ def add_recurse(options): if not ftime_match(db,filename,ftime): #file content changed add_single(conn,filename,change=True) - + conn.commit() return @@ -116,7 +117,6 @@ def add_single(conn,filename,change=False,hash=None,minsize=0): else: db.execute("INSERT INTO list(file,date,hash,size,mime)\ VALUES(?,?,?,?,?)",(filename,ftime,hash,fsize,mime)) - conn.commit() return def is_listed(db,filename): @@ -124,6 +124,16 @@ def is_listed(db,filename): count=db.fetchall() return count[0][0]>0 +def get_folder_contents(db,path): + ''' return the contents of the folder ''' + files=[] + db.execute("SELECT file FROM list where file LIKE ?",(path+'%',)) + for row in db: + base=row[0].replace(path,'',1) + if base.find('/')==-1: + files.append(base) + return files + def ftime_match(db,filename,ftime): db.execute("SELECT date FROM list where file == ?",(filename,)) count=db.fetchall()