Permalink
Browse files

fs, bugfix: fix fs stat when path endsWith slash (#371)

  • Loading branch information...
ngot authored and xicilion committed Nov 8, 2017
1 parent e067af4 commit 2bdd279eae7e52f136d128d123f7eb2d09cc3e04
Showing with 18 additions and 8 deletions.
  1. +6 −0 fibjs/src/fs/Stat.cpp
  2. +12 −8 test/fs_test.js
View
@@ -86,6 +86,12 @@ void Stat::fill(exlib::string path, BY_HANDLE_FILE_INFORMATION& fd)
result_t Stat::getStat(exlib::string path)
{
result_t hr = path_base::normalize(path, path);
if (hr < 0) {
return hr;
}
if (path.length() > 0 && isWin32PathSlash(path.c_str()[path.length() - 1]))
path.resize(path.length() - 1);
WIN32_FIND_DATAW fd;
HANDLE hFind;
View
@@ -12,7 +12,7 @@ var isWin32 = process.platform === 'win32';
function unlink(pathname) {
try {
fs.rmdir(pathname);
} catch (e) {}
} catch (e) { }
}
var pathname = 'test_dir' + vmid;
@@ -30,7 +30,7 @@ describe('fs', () => {
after(() => {
try {
fs.unlink(path.join(__dirname, 'unzip_test.zip'));
} catch (e) {}
} catch (e) { }
});
it("stat", () => {
@@ -41,6 +41,14 @@ describe('fs', () => {
assert.equal(st.isExecutable(), true);
assert.equal(st.isReadable(), true);
assert.equal(st.isWritable(), true);
st = fs.stat(path.join(__dirname, 'abc', '../'));
assert.equal(st.isDirectory(), true);
assert.equal(st.isFile(), false);
assert.equal(st.isExecutable(), true);
assert.equal(st.isReadable(), true);
assert.equal(st.isWritable(), true);
});
it("file open & close", () => {
@@ -190,9 +198,7 @@ describe('fs', () => {
fs.chown(fn, 23, 45)
});
else {
assert.doesNotThrow(function () {
fs.chown(fn, 23, 45)
});
assert.doesNotThrow(() => fs.chown(fn, 23, 45));
var st = fs.stat(fn);
assert.equal(st.uid, 23);
assert.equal(st.gid, 45);
@@ -211,9 +217,7 @@ describe('fs', () => {
fs.lchown(fn, 23, 45)
});
else {
assert.doesNotThrow(function () {
fs.lchown(fn, 23, 45)
});
assert.doesNotThrow(() => fs.lchown(fn, 23, 45));
var st = fs.stat(path.join(__dirname, 'fs_test.js'));
var lst = fs.lstat(fn);
assert.notEqual(st.uid, 23);

0 comments on commit 2bdd279

Please sign in to comment.