Skip to content

Commit

Permalink
Merge pull request #77 from RobotCaleb/FixExtraction
Browse files Browse the repository at this point in the history
Extract archive to temp path, copy to destination when done
  • Loading branch information
Geoffrey Lehée committed Feb 2, 2016
2 parents 4792bfd + 89d224f commit 0edd69a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
28 changes: 26 additions & 2 deletions sublimall/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .utils import is_win
from .utils import get_7za_bin
from .utils import generate_temp_filename
from .utils import generate_temp_path


class Archiver:
Expand Down Expand Up @@ -48,6 +49,23 @@ def _safe_move(self, source, destination):
if os.path.exists(source):
shutil.move(source, destination)

# shutil.copytree fails if dst exists
def _copy_tree(self, src, dst, symlinks=False, ignore=None):
logger.info("Copy %s to %s" % (src, dst))
if not os.path.exists(dst):
os.makedirs(dst)
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
self._copy_tree(s, d, symlinks, ignore)
else:
if not os.path.exists(d) or os.stat(src).st_mtime - os.stat(dst).st_mtime > 1:
try:
shutil.copy2(s, d)
except (Error) as why:
logger.error('shutil.copy2 - %s' % why)

def _get_7za_executable(self):
"""
Returns absolute 7za executable path
Expand Down Expand Up @@ -221,9 +239,15 @@ def unpack_packages(self, input_file, output_dir=None, password=None):
"""
if output_dir is None:
output_dir = self._get_output_dir()
logger.info('Extract in %s directory' % output_dir)
temp_dir = generate_temp_path()
logger.info('Extract in %s directory' % temp_dir)
self._run_executable(
'x',
password=password,
input_file=input_file,
output_dir=output_dir)
output_dir=temp_dir)
logger.info('Copy from %s to %s' % (temp_dir, output_dir))
self._copy_tree(temp_dir, output_dir)
logger.info('Remove %s' % temp_dir)
self._safe_rmtree(temp_dir)

2 changes: 1 addition & 1 deletion sublimall/commands/retrieve_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def unpack(self):
archiver.remove_backup_dirs()

self.set_message(u"Your Sublime Text has been synced !")
logger.info('Finised')
logger.info('Finished')

if self._package_control_has_packages():
message_lines = [
Expand Down
4 changes: 4 additions & 0 deletions sublimall/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ def get_7za_bin():
def generate_temp_filename():
return os.path.join(
tempfile.gettempdir(), 'sublime-sync_%s.zip' % str(uuid.uuid4()))

def generate_temp_path():
return os.path.join(
tempfile.gettempdir(), 'sublime-sync_%s' % str(uuid.uuid4()))

0 comments on commit 0edd69a

Please sign in to comment.