Skip to content

Commit 89d224f

Browse files
committed
Extract archive to temp path, copy to destination when done
1 parent 4641dad commit 89d224f

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

sublimall/archiver.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .utils import is_win
1212
from .utils import get_7za_bin
1313
from .utils import generate_temp_filename
14+
from .utils import generate_temp_path
1415

1516

1617
class Archiver:
@@ -48,6 +49,23 @@ def _safe_move(self, source, destination):
4849
if os.path.exists(source):
4950
shutil.move(source, destination)
5051

52+
# shutil.copytree fails if dst exists
53+
def _copy_tree(self, src, dst, symlinks=False, ignore=None):
54+
logger.info("Copy %s to %s" % (src, dst))
55+
if not os.path.exists(dst):
56+
os.makedirs(dst)
57+
for item in os.listdir(src):
58+
s = os.path.join(src, item)
59+
d = os.path.join(dst, item)
60+
if os.path.isdir(s):
61+
self._copy_tree(s, d, symlinks, ignore)
62+
else:
63+
if not os.path.exists(d) or os.stat(src).st_mtime - os.stat(dst).st_mtime > 1:
64+
try:
65+
shutil.copy2(s, d)
66+
except (Error) as why:
67+
logger.error('shutil.copy2 - %s' % why)
68+
5169
def _get_7za_executable(self):
5270
"""
5371
Returns absolute 7za executable path
@@ -221,9 +239,15 @@ def unpack_packages(self, input_file, output_dir=None, password=None):
221239
"""
222240
if output_dir is None:
223241
output_dir = self._get_output_dir()
224-
logger.info('Extract in %s directory' % output_dir)
242+
temp_dir = generate_temp_path()
243+
logger.info('Extract in %s directory' % temp_dir)
225244
self._run_executable(
226245
'x',
227246
password=password,
228247
input_file=input_file,
229-
output_dir=output_dir)
248+
output_dir=temp_dir)
249+
logger.info('Copy from %s to %s' % (temp_dir, output_dir))
250+
self._copy_tree(temp_dir, output_dir)
251+
logger.info('Remove %s' % temp_dir)
252+
self._safe_rmtree(temp_dir)
253+

sublimall/commands/retrieve_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def unpack(self):
223223
archiver.remove_backup_dirs()
224224

225225
self.set_message(u"Your Sublime Text has been synced !")
226-
logger.info('Finised')
226+
logger.info('Finished')
227227

228228
if self._package_control_has_packages():
229229
message_lines = [

sublimall/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@ def get_7za_bin():
7777
def generate_temp_filename():
7878
return os.path.join(
7979
tempfile.gettempdir(), 'sublime-sync_%s.zip' % str(uuid.uuid4()))
80+
81+
def generate_temp_path():
82+
return os.path.join(
83+
tempfile.gettempdir(), 'sublime-sync_%s' % str(uuid.uuid4()))

0 commit comments

Comments
 (0)