HaxeFoundation / HaxeFoundation/haxe

Haxe/Neko sys.FileSystem.createDirectory fails on UNC-Paths on haxe 4.0.0

Open
#6,941 2 comments 0 reactions 1 assignee Claimed by @Aurel300 View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

I try too create a Folder on a network-share (permissions set etc.) like so:

static function main() {
var paths = ['D:\\share\\', '\\\\localhost\\share\\'];
var i = 0;
try {
for (r in paths) {
if (sys.FileSystem.exists(r)) {
sys.FileSystem.createDirectory(r + '\\temp$i');
i++;
trace('dir created');
}
}
} catch (e: Dynamic) {
trace(e);
}
}

it fails cause of

public static function createDirectory( path : String ) : Void

does not check for UNC-Paths it trys too create a folder "\\" and it trys too create the server-part of the UNC-Path also "\\\\localhost\\"

quick workaround for me is too check if the path starts with a single "\\" - skip it and skip the next part as it is the server:

public static function createDirectory( path : String ) : Void {
var skipUNCServer = false;
var path = haxe.io.Path.addTrailingSlash(path);
var _p = null;
var parts = [];
while (path != (_p = haxe.io.Path.directory(path))) {
parts.unshift(path);
path = _p;
}
for (part in parts) {
if (part == '\\') {
skipUNCServer = true;
continue; //its UNC-Path - skip it
}
if (skipUNCServer) {
skipUNCServer = false;
continue; //skipped UNC-Path and Server
}
if (part.charCodeAt(part.length - 1) != ":".code && !exists(part)) {
sys_create_dir( untyped part.__s, 493 );
}
}
}

but it could potentially fail on other FileSystem-functions too!
I did not check on older versions but guess the functions itself was untouched quite a while?

Hope I could help a bit!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.