Skip to content

Commit

Permalink
Fix zip
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Apr 19, 2024
1 parent 3c6c6a5 commit 154ee18
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ jobs:
- name: Check base usage
run: |
hx-download latest
dir releases
dir versions
hx-download 4.3.4
dir releases
dir versions
hx-download nightly 569e52e
dir releases
dir versions
hx-select dev
haxe --version
dir current
haxe.exe --version
Binary file modified build/download.hxb
Binary file not shown.
Binary file modified build/select.hxb
Binary file not shown.
14 changes: 6 additions & 8 deletions src/HaxeDownload.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ class HaxeDownload {
final path = Path.join([Utils.releasesDir, filename]);

DownloadHelper.download(url + filename, path, () -> {
trace('Downloaded $filename as $alias');
Sys.println('Downloaded $filename');
final out = DownloadHelper.extract(path);
FileSystem.deleteFile(path);

final versionPath = Path.join([Utils.versionsDir, alias]);
try FileSystem.deleteFile(versionPath) catch(_) {}
FileSync.symlink(Path.join([FileSystem.absolutePath(Utils.releasesDir), out]), versionPath);
trace('Done');
Sys.println('Installed $filename as $alias');
});
}

Expand Down Expand Up @@ -110,7 +110,7 @@ class DownloadHelper {
public static function extract(path:String):Null<String> {
final pathData = new Path(path);
final filename = pathData.file + (pathData.ext == null ? "" : "." + pathData.ext);
trace('Extracting $filename...');
Sys.println('Extracting $filename...');

return switch (Path.extension(filename)) {
case "zip": new ZipExtractor(File.read(path, true)).extract(pathData.dir);
Expand Down Expand Up @@ -154,7 +154,7 @@ class TarExtractor extends format.tar.Reader {

if (FileSystem.exists(path)) {
// TODO: allow overwriting
trace('Output already exists; skipping');
Sys.println('Output already exists; skipping');
return ret;
}
}
Expand Down Expand Up @@ -196,24 +196,22 @@ class ZipExtractor {

for (e in zip) {
final path = Path.join([dest, e.fileName]);
trace(e.fileName, path);

if (StringTools.endsWith(e.fileName, '/')) {
if (ret == null) {
ret = e.fileName;
trace(ret);

if (FileSystem.exists(path)) {
// TODO: allow overwriting
trace('Output already exists; skipping');
Sys.println('Output already exists; skipping');
return ret;
}
}

FileSystem.createDirectory(path);
} else {
final out = File.write(path, true);
out.writeBytes(e.data, 0, e.fileSize);
out.writeBytes(haxe.zip.Reader.unzip(e), 0, e.fileSize);
out.close();
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Utils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getReleaseUrl(v:String):Array<String> {
case "Mac":
['https://github.com/HaxeFoundation/haxe/releases/download/$v/', 'haxe-$v-osx.tar.gz'];
case "Windows":
['https://github.com/HaxeFoundation/haxe/releases/download/$v/', 'haxe-$v-windows64.zip'];
['https://github.com/HaxeFoundation/haxe/releases/download/$v/', 'haxe-$v-win64.zip'];
case os: throw 'OS $os is not supported (yet)';
}
}
Expand All @@ -39,6 +39,7 @@ function getVersions():Array<String> {
return FileSystem.readDirectory(versionsDir);
}

// TODO: windows vs symlinks
function hasVersion(v:String):Bool {
final dir = Path.join([versionsDir, v]);
return FileSystem.isDirectory(dir);
Expand All @@ -60,6 +61,7 @@ function selectRelease(r:String):Void {
link(dir);
}

// TODO: unix vs windows
private function unlinkCurrent():Void {
inline function unlink(f:String) {
try FileSystem.deleteFile('$currentDir/$f') catch(_) {}
Expand All @@ -70,6 +72,7 @@ private function unlinkCurrent():Void {
unlink('std');
}

// TODO: unix vs windows
private function link(dir:String):Void {
if (!FileSystem.exists(currentDir)) FileSystem.createDirectory(currentDir);
FileSync.symlink(Path.join(["..", dir, "haxe"]), Path.join([currentDir, "haxe"]));
Expand Down

0 comments on commit 154ee18

Please sign in to comment.