feat(electron): fix windows path

This commit is contained in:
Tienson Qin
2021-01-27 21:38:18 +08:00
parent aad09df55c
commit 66a545c306
2 changed files with 20 additions and 2 deletions

View File

@@ -132,11 +132,17 @@
[repo-url file content]
(let [electron-local-repo? (and (util/electron?)
(config/local-db? repo-url))
;; FIXME: store relative path in db
file (cond
(and electron-local-repo? (util/win32?))
(and electron-local-repo?
util/win32?
(utils/win32 file))
file
electron-local-repo?
(and electron-local-repo? util/win32?)
(str (config/get-repo-dir repo-url) "/" file)
(and electron-local-repo? (not= "/" (first file)))
(str (config/get-repo-dir repo-url) "/" file)
:else

View File

@@ -192,3 +192,15 @@ export const reversePatch = patch => {
length2: patchObj.length1
}));
};
// Copied from https://github.com/sindresorhus/path-is-absolute/blob/main/index.js
export const win32 = path => {
// https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
var splitDeviceRe = /^([a-zA-Z]:|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)?([\\/])?([\s\S]*?)$/;
var result = splitDeviceRe.exec(path);
var device = result[1] || '';
var isUnc = Boolean(device && device.charAt(1) !== ':');
// UNC paths are always absolute
return Boolean(result[2] || isUnc);
}