diff --git a/medusa/helpers/__init__.py b/medusa/helpers/__init__.py
index ec4865d76c..7bb23c5e23 100644
--- a/medusa/helpers/__init__.py
+++ b/medusa/helpers/__init__.py
@@ -67,6 +67,11 @@
log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())
+try:
+ import reflink
+except ImportError:
+ reflink = None
+
def indent_xml(elem, level=0):
"""Do our pretty printing and make Matt very happy."""
@@ -422,6 +427,68 @@ def move_and_symlink_file(src_file, dest_file):
copy_file(src_file, dest_file)
+def reflink_file(src_file, dest_file):
+ """Copy a file from source to destination with a reference link.
+
+ :param src_file: Source file
+ :type src_file: str
+ :param dest_file: Destination file
+ :type dest_file: str
+ """
+ try:
+ if reflink is None:
+ raise NotImplementedError()
+ reflink.reflink(src_file.encode('utf-8'), dest_file.encode('utf-8')) # NOTE: remove when https://goo.gl/BMn8EC is merged.
+ except reflink.ReflinkImpossibleError as msg:
+ if msg.args[0] == 'EOPNOTSUPP':
+ log.warning(
+ u'Failed to create reference link of {source} at {destination}.'
+ u' Error: Filesystem or OS has not implemented reflink. Copying instead', {
+ 'source': src_file,
+ 'destination': dest_file,
+ }
+ )
+ copy_file(src_file, dest_file)
+ elif msg.args[0] == 'EXDEV':
+ log.warning(
+ u'Failed to create reference link of {source} at {destination}.'
+ u' Error: Can not reflink between two devices. Copying instead', {
+ 'source': src_file,
+ 'destination': dest_file,
+ }
+ )
+ copy_file(src_file, dest_file)
+ else:
+ log.warning(
+ u'Failed to create reflink of {source} at {destination}.'
+ u' Error: {error!r}. Copying instead', {
+ 'source': src_file,
+ 'destination': dest_file,
+ 'error': msg,
+ }
+ )
+ copy_file(src_file, dest_file)
+ except NotImplementedError:
+ log.warning(
+ u'Failed to create reference link of {source} at {destination}.'
+ u' Error: Filesystem does not support reflink or reflink is not installed. Copying instead', {
+ 'source': src_file,
+ 'destination': dest_file,
+ }
+ )
+ copy_file(src_file, dest_file)
+ except IOError as msg:
+ log.warning(
+ u'Failed to create reflink of {source} at {destination}.'
+ u' Error: {error!r}. Copying instead', {
+ 'source': src_file,
+ 'destination': dest_file,
+ 'error': msg,
+ }
+ )
+ copy_file(src_file, dest_file)
+
+
def make_dirs(path):
"""Create any folders that are missing and assigns them the permissions of their parents.
diff --git a/themes-default/legacy/views/config_postProcessing.mako b/themes-default/legacy/views/config_postProcessing.mako
index 5606e8f965..68ca184c12 100644
--- a/themes-default/legacy/views/config_postProcessing.mako
+++ b/themes-default/legacy/views/config_postProcessing.mako
@@ -2,6 +2,7 @@
<%!
import os.path
import datetime
+ import pkgutil
from medusa import app
from medusa.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from medusa.common import Quality, qualityPresets, statusStrings, qualityPresetStrings, cpu_presets, MULTI_EP_STRINGS
@@ -62,10 +63,17 @@
Processing Method:
@@ -76,6 +84,7 @@
diff --git a/themes-default/legacy/views/home_postprocess.mako b/themes-default/legacy/views/home_postprocess.mako
index 94348148c1..6b256242b7 100644
--- a/themes-default/legacy/views/home_postprocess.mako
+++ b/themes-default/legacy/views/home_postprocess.mako
@@ -1,5 +1,6 @@
<%inherit file="/layouts/main.mako"/>
<%!
+ import pkgutil
from medusa import app
%>
<%block name="content">
@@ -32,10 +33,17 @@
|
diff --git a/themes-default/slim/views/config_postProcessing.mako b/themes-default/slim/views/config_postProcessing.mako
index 5606e8f965..68ca184c12 100644
--- a/themes-default/slim/views/config_postProcessing.mako
+++ b/themes-default/slim/views/config_postProcessing.mako
@@ -2,6 +2,7 @@
<%!
import os.path
import datetime
+ import pkgutil
from medusa import app
from medusa.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from medusa.common import Quality, qualityPresets, statusStrings, qualityPresetStrings, cpu_presets, MULTI_EP_STRINGS
@@ -62,10 +63,17 @@
Processing Method:
@@ -76,6 +84,7 @@
diff --git a/themes-default/slim/views/home_postprocess.mako b/themes-default/slim/views/home_postprocess.mako
index 94348148c1..6b256242b7 100644
--- a/themes-default/slim/views/home_postprocess.mako
+++ b/themes-default/slim/views/home_postprocess.mako
@@ -1,5 +1,6 @@
<%inherit file="/layouts/main.mako"/>
<%!
+ import pkgutil
from medusa import app
%>
<%block name="content">
@@ -32,10 +33,17 @@
|
diff --git a/themes/dark/templates/config_postProcessing.mako b/themes/dark/templates/config_postProcessing.mako
index 5606e8f965..68ca184c12 100644
--- a/themes/dark/templates/config_postProcessing.mako
+++ b/themes/dark/templates/config_postProcessing.mako
@@ -2,6 +2,7 @@
<%!
import os.path
import datetime
+ import pkgutil
from medusa import app
from medusa.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from medusa.common import Quality, qualityPresets, statusStrings, qualityPresetStrings, cpu_presets, MULTI_EP_STRINGS
@@ -62,10 +63,17 @@
Processing Method:
@@ -76,6 +84,7 @@
diff --git a/themes/dark/templates/home_postprocess.mako b/themes/dark/templates/home_postprocess.mako
index 94348148c1..6b256242b7 100644
--- a/themes/dark/templates/home_postprocess.mako
+++ b/themes/dark/templates/home_postprocess.mako
@@ -1,5 +1,6 @@
<%inherit file="/layouts/main.mako"/>
<%!
+ import pkgutil
from medusa import app
%>
<%block name="content">
@@ -32,10 +33,17 @@
|
diff --git a/themes/legacy/templates/config_postProcessing.mako b/themes/legacy/templates/config_postProcessing.mako
index 5606e8f965..68ca184c12 100644
--- a/themes/legacy/templates/config_postProcessing.mako
+++ b/themes/legacy/templates/config_postProcessing.mako
@@ -2,6 +2,7 @@
<%!
import os.path
import datetime
+ import pkgutil
from medusa import app
from medusa.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from medusa.common import Quality, qualityPresets, statusStrings, qualityPresetStrings, cpu_presets, MULTI_EP_STRINGS
@@ -62,10 +63,17 @@
Processing Method:
@@ -76,6 +84,7 @@
diff --git a/themes/legacy/templates/home_postprocess.mako b/themes/legacy/templates/home_postprocess.mako
index 94348148c1..6b256242b7 100644
--- a/themes/legacy/templates/home_postprocess.mako
+++ b/themes/legacy/templates/home_postprocess.mako
@@ -1,5 +1,6 @@
<%inherit file="/layouts/main.mako"/>
<%!
+ import pkgutil
from medusa import app
%>
<%block name="content">
@@ -32,10 +33,17 @@
|
diff --git a/themes/light/templates/config_postProcessing.mako b/themes/light/templates/config_postProcessing.mako
index 5606e8f965..68ca184c12 100644
--- a/themes/light/templates/config_postProcessing.mako
+++ b/themes/light/templates/config_postProcessing.mako
@@ -2,6 +2,7 @@
<%!
import os.path
import datetime
+ import pkgutil
from medusa import app
from medusa.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from medusa.common import Quality, qualityPresets, statusStrings, qualityPresetStrings, cpu_presets, MULTI_EP_STRINGS
@@ -62,10 +63,17 @@
Processing Method:
@@ -76,6 +84,7 @@
diff --git a/themes/light/templates/home_postprocess.mako b/themes/light/templates/home_postprocess.mako
index 94348148c1..e88ba53e0c 100644
--- a/themes/light/templates/home_postprocess.mako
+++ b/themes/light/templates/home_postprocess.mako
@@ -1,5 +1,6 @@
<%inherit file="/layouts/main.mako"/>
<%!
+ import pkgutl
from medusa import app
%>
<%block name="content">
@@ -32,10 +33,17 @@
|