Browse Source

Check free diskspace before starting moving files

fix #3893
pull/4201/head
Ruud 11 years ago
parent
commit
da9d2b5ed8
  1. 22
      couchpotato/core/helpers/variable.py
  2. 11
      couchpotato/core/plugins/renamer.py

22
couchpotato/core/helpers/variable.py

@ -382,6 +382,28 @@ def getFreeSpace(directories):
return free_space
def getSize(paths):
single = not isinstance(paths, (tuple, list))
if single:
paths = [paths]
total_size = 0
for path in paths:
path = sp(path)
if os.path.isdir(path):
total_size = 0
for dirpath, _, filenames in os.walk(path):
for f in filenames:
total_size += os.path.getsize(sp(os.path.join(dirpath, f)))
elif os.path.isfile(path):
total_size += os.path.getsize(path)
return total_size / 1048576 # MB
def find(func, iterable):
for item in iterable:
if func(item):

11
couchpotato/core/plugins/renamer.py

@ -10,7 +10,8 @@ from couchpotato.api import addApiView
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
from couchpotato.core.helpers.encoding import toUnicode, ss, sp
from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \
getImdb, link, symlink, tryInt, splitString, fnEscape, isSubFolder, getIdentifier, randomString
getImdb, link, symlink, tryInt, splitString, fnEscape, isSubFolder, \
getIdentifier, randomString, getFreeSpace, getSize
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
@ -279,6 +280,7 @@ class Renamer(Plugin):
except:
log.error('Failed getting category label: %s', traceback.format_exc())
# Find subtitle for renaming
group['before_rename'] = []
fireEvent('renamer.before', group)
@ -546,6 +548,13 @@ class Renamer(Plugin):
(not keep_original or self.fileIsAdded(current_file, group)):
remove_files.append(current_file)
total_space, available_space = getFreeSpace(destination)
renaming_size = getSize(rename_files.keys())
if renaming_size > available_space:
log.error('Not enough space left, need %s MB but only %s MB available', (renaming_size, available_space))
self.tagRelease(group = group, tag = 'not_enough_space')
continue
# Remove files
delete_folders = []
for src in remove_files:

Loading…
Cancel
Save