Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract archive to temp path, copy to destination when done #77

Merged
merged 1 commit into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -223,7 +223,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()))