Merge pull request #144 from vibe-d/fix_makefileinfo_range_violation
Fix makeFileInfo range violation
This commit is contained in:
commit
b7669868c0
|
@ -733,11 +733,13 @@ private FileInfo makeFileInfo(DirEntry ent)
|
||||||
import std.algorithm.comparison : among;
|
import std.algorithm.comparison : among;
|
||||||
|
|
||||||
FileInfo ret;
|
FileInfo ret;
|
||||||
if (!ent.name.length) return ret;
|
string fullname = ent.name;
|
||||||
|
if (ent.name.length) {
|
||||||
auto fullname = ent.name[$-1].among('/', '\\') ? ent.name[0 .. $-1] : ent.name;
|
if (ent.name[$-1].among('/', '\\'))
|
||||||
ret.name = baseName(fullname);
|
fullname = ent.name[0 .. $-1];
|
||||||
if (ret.name.length == 0) ret.name = fullname;
|
ret.name = baseName(fullname);
|
||||||
|
if (ret.name.length == 0) ret.name = fullname;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ret.isFile = ent.isFile;
|
ret.isFile = ent.isFile;
|
||||||
|
@ -755,7 +757,31 @@ private FileInfo makeFileInfo(DirEntry ent)
|
||||||
import core.sys.windows.windows : FILE_ATTRIBUTE_HIDDEN;
|
import core.sys.windows.windows : FILE_ATTRIBUTE_HIDDEN;
|
||||||
ret.hidden = (ent.attributes & FILE_ATTRIBUTE_HIDDEN) != 0;
|
ret.hidden = (ent.attributes & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||||
}
|
}
|
||||||
else ret.hidden = ret.name[0] == '.' && ret.name != "." && ret.name != "..";
|
else ret.hidden = ret.name.length > 1 && ret.name[0] == '.' && ret.name != "..";
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version (Windows) {} else unittest {
|
||||||
|
void test(string name_in, string name_out, bool hidden) {
|
||||||
|
auto de = DirEntry(name_in);
|
||||||
|
assert(makeFileInfo(de).hidden == hidden);
|
||||||
|
assert(makeFileInfo(de).name == name_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testCreate(string name_in, string name_out, bool hidden)
|
||||||
|
{
|
||||||
|
if (name_in.endsWith("/"))
|
||||||
|
createDirectory(name_in);
|
||||||
|
else writeFileUTF8(NativePath(name_in), name_in);
|
||||||
|
scope (exit) removeFile(name_in);
|
||||||
|
test(name_in, name_out, hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(".", ".", false);
|
||||||
|
test("..", "..", false);
|
||||||
|
testCreate(".test_foo", ".test_foo", true);
|
||||||
|
test("./", ".", false);
|
||||||
|
testCreate(".test_foo/", ".test_foo", true);
|
||||||
|
test("/", "", false);
|
||||||
|
}
|
||||||
|
|
|
@ -621,7 +621,7 @@ mixin(tracer);
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
If the read readiness can be determined immediately, it will be
|
If the read readiness can be determined immediately, it will be
|
||||||
returned as WaitForDataAsyncStatus.sataAvailable` or
|
returned as `WaitForDataAsyncStatus.dataAvailable` or
|
||||||
`WaitForDataAsyncStatus.noModeData` and the callback will not be
|
`WaitForDataAsyncStatus.noModeData` and the callback will not be
|
||||||
invoked. Otherwise `WaitForDataAsyncStatus.waiting` is returned
|
invoked. Otherwise `WaitForDataAsyncStatus.waiting` is returned
|
||||||
and the callback will be invoked once the status can be
|
and the callback will be invoked once the status can be
|
||||||
|
|
Loading…
Reference in a new issue