Skip to content

Commit

Permalink
Fix "cross-device link not permitted" download error (#40)
Browse files Browse the repository at this point in the history
* Fix "cross-device link not permitted" download error
* Try delete tmp file ref to prevent TEXT FILE BUSY error
* Add download delay?
* Decrease arbitrary wait timeout
  • Loading branch information
pcj authored Oct 26, 2020
1 parent f9e3154 commit 0d267c4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.6.4 (Mon Oct 25 2020)

- Fix https://github.com/stackb/bazel-stack-vscode/issues/36.

## 0.6.3 (Mon Oct 25 2020)

- Integrate gostarlark go to definition for bazel labels
Expand Down
45 changes: 44 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bazel-stack-vscode",
"displayName": "bazel-stack-vscode",
"description": "Bazel Support for Visual Studio Code",
"version": "0.6.3",
"version": "0.6.4",
"publisher": "StackBuild",
"license": "Apache-2.0",
"icon": "stackb-full.png",
Expand Down Expand Up @@ -1145,13 +1145,14 @@
"google-auth-library": "6.1.0",
"graceful-fs": "4.2.4",
"luxon": "1.24.1",
"mv": "^2.1.1",
"node-fetch": "2.6.0",
"portfinder": "1.0.28",
"protobufjs": "6.10.1",
"request": "2.88.2",
"sha256-file": "1.0.0",
"shiki-themes": "^0.2.6",
"shiki": "^0.2.6",
"shiki-themes": "^0.2.6",
"simple-lightbox": "2.1.0",
"slash": "3.0.0",
"strip-ansi": "^6.0.0",
Expand All @@ -1174,6 +1175,7 @@
"@types/graceful-fs": "4.1.2",
"@types/luxon": "1.24.3",
"@types/mocha": "^7.0.2",
"@types/mv": "2.1.0",
"@types/node-fetch": "1.6.9",
"@types/node": "^13.11.0",
"@types/request": "2.48.5",
Expand Down
22 changes: 14 additions & 8 deletions src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as octokit from '@octokit/rest';
import { ReposListReleasesResponseData } from '@octokit/types';
import * as fs from 'graceful-fs';
import * as mv from 'mv';
import * as path from 'path';
import * as request from 'request';
import * as sha256File from 'sha256-file';
Expand Down Expand Up @@ -233,9 +234,6 @@ export async function downloadAsset(url: string, filename: string, mode: number,
return Promise.reject(`${filename} already exists and matches requested sha256 ${sha256}`);
}
}
fs.mkdirSync(path.dirname(filename), {
recursive: true,
});

const tmpFile = tmp.fileSync();

Expand All @@ -262,7 +260,7 @@ export async function downloadAsset(url: string, filename: string, mode: number,
if (err) {
reject(err);
return;
}
}
if (sha256) {
const actual = sha256File(tmpFile.name);
if (actual !== sha256) {
Expand All @@ -272,12 +270,20 @@ export async function downloadAsset(url: string, filename: string, mode: number,
}
resolve();
});

}).then(() => {
fs.chmodSync(tmpFile.name, mode);
fs.renameSync(tmpFile.name, filename);
console.log(`Renamed ${tmpFile.name} -> ${filename}`);
tmpFile.removeCallback();
return new Promise((resolve, reject) => {
mv(tmpFile.name, filename, { mkdirp: true }, err => {
if (err) {
reject(err);
return;
}
console.log(`Renamed ${tmpFile.name} -> ${filename}`);
tmpFile.removeCallback();
setTimeout(() => resolve(), 250);
});
});
});
}

Expand Down

0 comments on commit 0d267c4

Please sign in to comment.