mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-03 07:48:46 +08:00
fix: fix path issues under win32 platform
This commit is contained in:
parent
5c636d4fd2
commit
d80f2fa847
@ -19,6 +19,7 @@
|
||||
const { is_valid_path } = require("../../filesystem/validation");
|
||||
const { is_valid_uuid4 } = require("../../helpers");
|
||||
const { Context } = require("../../util/context");
|
||||
const { PathBuilder } = require("../../util/pathutil");
|
||||
const APIError = require("../APIError");
|
||||
const _path = require('path');
|
||||
|
||||
@ -73,6 +74,7 @@ module.exports = class FSNodeParam {
|
||||
});
|
||||
}
|
||||
|
||||
return await fs.node({ path: _path.resolve('/', uidOrPath) });
|
||||
const resolved_path = PathBuilder.resolve(uidOrPath, { puterfs: true });
|
||||
return await fs.node({ path: resolved_path });
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ const { BaseDatabaseAccessService } = require('./services/database/BaseDatabaseA
|
||||
const { LLRmNode } = require('./filesystem/ll_operations/ll_rmnode');
|
||||
const { Context } = require('./util/context');
|
||||
const { NodeUIDSelector } = require('./filesystem/node/selectors');
|
||||
const { PathBuilder } = require('./util/pathutil');
|
||||
|
||||
let systemfs = null;
|
||||
let services = null;
|
||||
@ -1155,8 +1156,12 @@ async function jwt_auth(req){
|
||||
async function mkdir(options){
|
||||
const fs = systemfs;
|
||||
|
||||
const dirpath = _path.dirname(_path.resolve('/', options.path));
|
||||
let target_name = _path.basename(_path.resolve('/', options.path));
|
||||
debugger;
|
||||
|
||||
const resolved_path = PathBuilder.resolve(options.path, { puterfs: true });
|
||||
|
||||
const dirpath = _path.dirname(resolved_path);
|
||||
let target_name = _path.basename(resolved_path);
|
||||
const overwrite = options.overwrite ?? false;
|
||||
const dedupe_name = options.dedupe_name ?? false;
|
||||
const immutable = options.immutable ?? false;
|
||||
@ -1182,7 +1187,7 @@ async function mkdir(options){
|
||||
|
||||
// dirpath not found
|
||||
if(parent === false && !create_missing_parents)
|
||||
throw "Target path not found";
|
||||
throw new Error("Target path not found");
|
||||
// create missing parent directories
|
||||
else if(parent === false && create_missing_parents){
|
||||
const dirs = _path.resolve('/', dirpath).split('/');
|
||||
@ -1206,7 +1211,7 @@ async function mkdir(options){
|
||||
// try setting parent again
|
||||
parent = await convert_path_to_fsentry(dirpath);
|
||||
if(parent === false)
|
||||
throw "Target path not found";
|
||||
throw new Error("Target path not found");
|
||||
}
|
||||
|
||||
// check permission
|
||||
|
@ -81,16 +81,6 @@ module.exports = eggspress('/readdir', {
|
||||
const no_thumbs = req.values.no_thumbs;
|
||||
const no_assocs = req.values.no_assocs;
|
||||
|
||||
{
|
||||
const fs = require('fs');
|
||||
fs.appendFileSync('/tmp/readdir.log',
|
||||
JSON.stringify({
|
||||
recursive,
|
||||
no_thumbs,
|
||||
no_assocs,
|
||||
}, null, 2) + '\n');
|
||||
}
|
||||
|
||||
const hl_readdir = new HLReadDir();
|
||||
const result = await hl_readdir.run({
|
||||
subject,
|
||||
|
@ -28,25 +28,40 @@ class PathBuilder extends AdvancedBase {
|
||||
path: require('path'),
|
||||
}
|
||||
|
||||
constructor() {
|
||||
constructor(parameters = {}) {
|
||||
super();
|
||||
if ( parameters.puterfs ) {
|
||||
this.modules.path =
|
||||
this.modules.path.posix;
|
||||
}
|
||||
this.path_ = '';
|
||||
}
|
||||
|
||||
static create () {
|
||||
return new PathBuilder();
|
||||
static create (parameters) {
|
||||
return new PathBuilder(parameters);
|
||||
}
|
||||
|
||||
static add (fragment, options) {
|
||||
return PathBuilder.create().add(fragment, options);
|
||||
}
|
||||
|
||||
static resolve (fragment) {
|
||||
const p = PathBuilder.create();
|
||||
static resolve (fragment, parameters = {}) {
|
||||
const { puterfs } = parameters;
|
||||
|
||||
const p = PathBuilder.create(parameters);
|
||||
const require = p.require;
|
||||
const node_path = require('path');
|
||||
fragment = node_path.resolve(fragment);
|
||||
return p.add(fragment).build();
|
||||
if ( process.platform === 'win32' && !parameters.puterfs ) {
|
||||
fragment = '/' + fragment.slice('c:\\'.length); // >:-(
|
||||
}
|
||||
let result = p.add(fragment).build();
|
||||
if ( puterfs && process.platform === 'win32' &&
|
||||
result.startsWith('\\')
|
||||
) {
|
||||
result = '/' + result.slice(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
add (fragment, options) {
|
||||
|
Loading…
Reference in New Issue
Block a user