Don't use ctime on unix system. Cleanup check a bit. close #2904
This commit is contained in:
1 parent
7af1d00ea2
commit
2066625bf0
3 files changed
+47
-51
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
from couchpotato.core.event import fireEvent, addEvent
|
from couchpotato.core.event import fireEvent, addEvent
|
||||||
from couchpotato.core.helpers.encoding import ss, toSafeString, \
|
from couchpotato.core.helpers.encoding import ss, toSafeString, \
|
||||||
toUnicode, sp
|
toUnicode, sp
|
||||||
from couchpotato.core.helpers.variable import getExt, md5, isLocalIP, scanForPassword
|
from couchpotato.core.helpers.variable import getExt, md5, isLocalIP, scanForPassword, tryInt
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
import requests
|
import requests
|
||||||
@@ -307,6 +307,42 @@ class Plugin(object):
|
|||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def checkFilesChanged(self, files, unchanged_for = 60):
|
||||||
|
now = time.time()
|
||||||
|
|
||||||
|
for cur_file in files:
|
||||||
|
|
||||||
|
# File got removed while checking
|
||||||
|
if not os.path.isfile(cur_file):
|
||||||
|
file_too_new = now
|
||||||
|
break
|
||||||
|
|
||||||
|
# File has changed in last 60 seconds
|
||||||
|
file_time = self.self.getFileTimes(cur_file)
|
||||||
|
for t in file_time:
|
||||||
|
if t > now - unchanged_for:
|
||||||
|
file_too_new = tryInt(time.time() - t)
|
||||||
|
break
|
||||||
|
|
||||||
|
if file_too_new:
|
||||||
|
break
|
||||||
|
|
||||||
|
if file_too_new:
|
||||||
|
try:
|
||||||
|
time_string = time.ctime(file_time[0])
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
time_string = time.ctime(file_time[1])
|
||||||
|
except:
|
||||||
|
time_string = 'unknown'
|
||||||
|
|
||||||
|
return file_too_new, time_string
|
||||||
|
|
||||||
|
return False, None
|
||||||
|
|
||||||
|
def getFileTimes(self, file_path):
|
||||||
|
return [os.path.getmtime(file_path), os.path.getctime(file_path) if os.name != 'posix' else 0]
|
||||||
|
|
||||||
def isDisabled(self):
|
def isDisabled(self):
|
||||||
return not self.isEnabled()
|
return not self.isEnabled()
|
||||||
|
|
||||||
|
|||||||
@@ -1127,29 +1127,9 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
|
|
||||||
# Check if archive is fresh and maybe still copying/moving/downloading, ignore files newer than 1 minute
|
# Check if archive is fresh and maybe still copying/moving/downloading, ignore files newer than 1 minute
|
||||||
if check_file_date:
|
if check_file_date:
|
||||||
file_too_new = False
|
files_too_new, time_string = self.checkFilesChanged(archive['files'])
|
||||||
for cur_file in archive['files']:
|
|
||||||
if not os.path.isfile(cur_file):
|
|
||||||
file_too_new = time.time()
|
|
||||||
break
|
|
||||||
file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)]
|
|
||||||
for t in file_time:
|
|
||||||
if t > time.time() - 60:
|
|
||||||
file_too_new = tryInt(time.time() - t)
|
|
||||||
break
|
|
||||||
|
|
||||||
if file_too_new:
|
|
||||||
break
|
|
||||||
|
|
||||||
if file_too_new:
|
|
||||||
try:
|
|
||||||
time_string = time.ctime(file_time[0])
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
time_string = time.ctime(file_time[1])
|
|
||||||
except:
|
|
||||||
time_string = 'unknown'
|
|
||||||
|
|
||||||
|
if files_too_new:
|
||||||
log.info('Archive seems to be still copying/moving/downloading or just copied/moved/downloaded (created on %s), ignoring for now: %s', (time_string, os.path.basename(archive['file'])))
|
log.info('Archive seems to be still copying/moving/downloading or just copied/moved/downloaded (created on %s), ignoring for now: %s', (time_string, os.path.basename(archive['file'])))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -291,41 +291,21 @@ class Scanner(Plugin):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# Check if movie is fresh and maybe still unpacking, ignore files newer than 1 minute
|
# Check if movie is fresh and maybe still unpacking, ignore files newer than 1 minute
|
||||||
file_too_new = False
|
if check_file_date:
|
||||||
for cur_file in group['unsorted_files']:
|
files_too_new, time_string = self.checkFilesChanged(group['unsorted_files'])
|
||||||
if not os.path.isfile(cur_file):
|
if files_too_new:
|
||||||
file_too_new = time.time()
|
log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s', (time_string, identifier))
|
||||||
break
|
|
||||||
file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)]
|
|
||||||
for t in file_time:
|
|
||||||
if t > time.time() - 60:
|
|
||||||
file_too_new = tryInt(time.time() - t)
|
|
||||||
break
|
|
||||||
|
|
||||||
if file_too_new:
|
# Delete the unsorted list
|
||||||
break
|
del group['unsorted_files']
|
||||||
|
|
||||||
if check_file_date and file_too_new:
|
continue
|
||||||
try:
|
|
||||||
time_string = time.ctime(file_time[0])
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
time_string = time.ctime(file_time[1])
|
|
||||||
except:
|
|
||||||
time_string = 'unknown'
|
|
||||||
|
|
||||||
log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s', (time_string, identifier))
|
|
||||||
|
|
||||||
# Delete the unsorted list
|
|
||||||
del group['unsorted_files']
|
|
||||||
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Only process movies newer than x
|
# Only process movies newer than x
|
||||||
if newer_than and newer_than > 0:
|
if newer_than and newer_than > 0:
|
||||||
has_new_files = False
|
has_new_files = False
|
||||||
for cur_file in group['unsorted_files']:
|
for cur_file in group['unsorted_files']:
|
||||||
file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)]
|
file_time = self.getFileTimes(cur_file)
|
||||||
if file_time[0] > newer_than or file_time[1] > newer_than:
|
if file_time[0] > newer_than or file_time[1] > newer_than:
|
||||||
has_new_files = True
|
has_new_files = True
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in new issue
Block a user