mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1556322 [automatic adding not sorted to last modified time stamp](https://bugs.launchpad.net/calibre/+bug/1556322)
This commit is contained in:
parent
26ee920fd8
commit
2733e4558f
@ -96,11 +96,17 @@ class Worker(Thread):
|
|||||||
# Must be a known ebook file type
|
# Must be a known ebook file type
|
||||||
self.is_filename_allowed(x)
|
self.is_filename_allowed(x)
|
||||||
]
|
]
|
||||||
data = {}
|
data = []
|
||||||
# Give any in progress copies time to complete
|
# Give any in progress copies time to complete
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
for fname in files:
|
def safe_mtime(x):
|
||||||
|
try:
|
||||||
|
return os.path.getmtime(os.path.join(self.path, x))
|
||||||
|
except EnvironmentError:
|
||||||
|
return time.time()
|
||||||
|
|
||||||
|
for fname in sorted(files, key=safe_mtime):
|
||||||
f = os.path.join(self.path, fname)
|
f = os.path.join(self.path, fname)
|
||||||
|
|
||||||
# Try opening the file for reading, if the OS prevents us, then at
|
# Try opening the file for reading, if the OS prevents us, then at
|
||||||
@ -141,7 +147,7 @@ class Worker(Thread):
|
|||||||
with open(opfpath, 'wb') as f:
|
with open(opfpath, 'wb') as f:
|
||||||
f.write(metadata_to_opf(mi))
|
f.write(metadata_to_opf(mi))
|
||||||
self.staging.add(fname)
|
self.staging.add(fname)
|
||||||
data[fname] = tdir
|
data.append((fname, tdir))
|
||||||
if data:
|
if data:
|
||||||
self.callback(data)
|
self.callback(data)
|
||||||
|
|
||||||
@ -208,7 +214,7 @@ class AutoAdder(QObject):
|
|||||||
duplicates = []
|
duplicates = []
|
||||||
added_ids = set()
|
added_ids = set()
|
||||||
|
|
||||||
for fname, tdir in data.iteritems():
|
for fname, tdir in data:
|
||||||
paths = [os.path.join(self.worker.path, fname)]
|
paths = [os.path.join(self.worker.path, fname)]
|
||||||
sz = os.path.join(tdir, 'size.txt')
|
sz = os.path.join(tdir, 'size.txt')
|
||||||
try:
|
try:
|
||||||
@ -277,7 +283,7 @@ class AutoAdder(QObject):
|
|||||||
num = len(ids)
|
num = len(ids)
|
||||||
count += num
|
count += num
|
||||||
|
|
||||||
for tdir in data.itervalues():
|
for fname, tdir in data:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(tdir)
|
shutil.rmtree(tdir)
|
||||||
except:
|
except:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user