Skip to content

Commit

Permalink
Merge pull request #3 from sublimelsp/fix/zip
Browse files Browse the repository at this point in the history
Fix zip unpacking on Windows
  • Loading branch information
LDAP authored Jun 11, 2023
2 parents 7bbe122 + 05c38f3 commit 7f8dee3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import tarfile
import tempfile
import time
import zipfile
from io import UnsupportedOperation

import requests
import sublime
Expand Down Expand Up @@ -103,10 +105,10 @@ def fetch_latest_release() -> None:

def code_action_insert_settings(server_setting_key: str, value: dict):
"""
Adds a server setting initiated via custom ltex-la codeAction.
Adds a server setting initiated via custom ltex-la codeAction.
Merges the settings if already present.
This function is used for the addToDictionary,... custom commands
:param server_setting_key: The key of the server setting
:param server_setting_key: The key of the server setting
(in "settings" block)
:type server_setting_key: str
:param value: A dict of "language": [settings] pairs
Expand Down Expand Up @@ -150,7 +152,7 @@ def basedir(cls) -> str:
def serverversion(cls) -> str:
"""
Returns the version of ltex-ls to use. Can be None if
no version is set in settings and no connection is available and
no version is set in settings and no connection is available and
and no server is available offline.
:param cls: The class
Expand Down Expand Up @@ -205,7 +207,7 @@ def install_or_update(cls) -> None:
shutil.rmtree(cls.basedir())
os.makedirs(cls.basedir())
with tempfile.TemporaryDirectory() as tempdir:
tar_path = os.path.join(tempdir, 'server.tar.gz')
archive_path = os.path.join(tempdir, 'server.tar.gz')

suffix = ".tar.gz" # platform-independent release
if os.getenv("JAVA_HOME") is None:
Expand All @@ -218,12 +220,17 @@ def install_or_update(cls) -> None:
suffix = "-windows-x64.zip"

download_file(GITHUB_DL_URL.format(cls.serverversion(), suffix),
tar_path,
archive_path,
show_download_progress)
sublime.status_message('ltex-ls: extracting')
tar = tarfile.open(tar_path, "r:gz")
tar.extractall(tempdir)
tar.close()
if suffix.endswith("tar.gz"):
archive = tarfile.open(archive_path, "r:gz")
elif suffix.endswith(".zip"):
archive = zipfile.ZipFile(archive_path)
else:
raise UnsupportedOperation()
archive.extractall(tempdir)
archive.close()
shutil.move(os.path.join(tempdir, SERVER_FOLDER_NAME
.format(cls.serverversion())),
cls.basedir())
Expand Down

0 comments on commit 7f8dee3

Please sign in to comment.