Skip to content

Commit 17af8a1

Browse files
committed
fix tar unzip bug
1 parent 8c36c59 commit 17af8a1

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/Compress.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class SevenZipper {
102102
this._event.emit('progress', 20, line);
103103
});
104104

105-
process.Run('tar', paramList);
105+
process.Run(this._tar_path(), paramList);
106106
});
107107
}
108108

@@ -154,13 +154,25 @@ export class SevenZipper {
154154
});
155155
}
156156

157+
private _is_tar(path: string) {
158+
return /\.tar$|\.tar\./.test(path);
159+
}
160+
161+
private _tar_path(): string {
162+
if (platform.osType() == 'win32') {
163+
return ResManager.instance().getMsysBinToolPath('tar');
164+
} else {
165+
return 'tar';
166+
}
167+
}
168+
157169
Unzip(zipFile: File, outDir?: File): Promise<Error | null> {
158170

159171
if (!zipFile.IsFile()) {
160172
throw new Error('\'' + zipFile.path + '\' is not exist');
161173
}
162174

163-
if (platform.osType() != 'win32' && zipFile.suffix.startsWith('tar')) {
175+
if (this._is_tar(zipFile.name)) {
164176
return this._unzip_tar(zipFile, outDir);
165177
} else {
166178
return this._unzip_zip_7z(zipFile, outDir);
@@ -174,15 +186,15 @@ export class SevenZipper {
174186
}
175187

176188
// use tar
177-
if (platform.osType() != 'win32' && zipFile.suffix.startsWith('tar')) {
189+
if (this._is_tar(zipFile.name)) {
178190

179191
let paramList: string[] = [];
180192

181193
paramList.push('-xvf');
182194
paramList.push(zipFile.path);
183195
paramList.push('-C', outDir ? outDir.path : zipFile.dir);
184196

185-
return child_process.execFileSync('tar', paramList).toString();
197+
return child_process.execFileSync(this._tar_path(), paramList).toString();
186198
}
187199
// use 7z
188200
else {

src/ResManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ export class ResManager extends events.EventEmitter {
439439
}
440440
}
441441

442+
getMsysBinToolPath(toolname: string): string {
443+
if (os.platform() == 'win32') {
444+
return File.fromArray([this.getBuilderDir().path, 'msys', 'bin', `${toolname}${exeSuffix()}`]).path;
445+
} else {
446+
return `${toolname}${exeSuffix()}`;
447+
}
448+
}
449+
442450
getBuilder(): File {
443451
return File.fromArray([this.getBuilderDir().path, 'bin', `unify_builder${exeSuffix()}`]);
444452
}

0 commit comments

Comments
 (0)