Skip to content
Snippets Groups Projects
Commit 9ece7993 authored by Tomasz Grabiec's avatar Tomasz Grabiec
Browse files

vfs: Fix lookup for paths ending with slash


For example, assuming the following file exists:

  /tmp/dir/x

..the following was sondiered absent:

  /tmp/dir/

..this was considered present:

  /tmp/dir

Signed-off-by: default avatarTomasz Grabiec <tgrabiec@cloudius-systems.com>
parent 858a2289
No related branches found
No related tags found
No related merge requests found
......@@ -123,7 +123,8 @@ autodepend = -MD -MT $@ -MP
do-sys-includes = $(foreach inc, $(sys-includes), -isystem $(inc))
boost-tests := tests/tst-rename.so
boost-tests := tests/tst-rename.so \
tests/tst-vfs.so
tests := tests/tst-pthread.so tests/tst-ramdisk.so tests/hello/Hello.class
tests += tests/tst-vblk.so tests/bench/bench.jar
......@@ -134,7 +135,8 @@ tests += tests/tst-fpu.so
tests += tests/tst-preempt.so
tests += tests/tst-tracepoint.so
tests += tests/tst-hub.so
tests += tests/tst-leak.so tests/tst-mmap.so tests/tst-vfs.so
tests += tests/tst-leak.so
tests += tests/tst-mmap.so
tests += tests/tst-mmap-file.so
tests += tests/tst-mutex.so
tests += tests/tst-sockets.so
......
......@@ -183,6 +183,10 @@ namei(char *path, struct dentry **dpp)
*/
while (*p == '/')
p++;
if (*p == '\0')
break;
for (i = 0; i < PATH_MAX; i++) {
if (*p == '\0' || *p == '/')
break;
......
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
#ifndef _TST_FS_HH
#define _TST_FS_HH
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
class TempDir : public fs::path
{
public:
TempDir() : fs::path(tmpnam(NULL)) {
fs::create_directories(*this);
}
virtual ~TempDir() {
fs::remove_all(*this);
}
};
#endif
#define BOOST_TEST_MODULE __file__
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <iostream>
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
#define BOOST_TEST_MODULE tst-rename
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/test/unit_test.hpp>
#include "tst-fs.hh"
namespace fs = boost::filesystem;
static const char *SECRET = "Hello, world";
class TempDir : public fs::path
{
public:
TempDir() : fs::path(tmpnam(NULL)) {
fs::create_directories(*this);
}
virtual ~TempDir() {
fs::remove_all(*this);
}
};
static std::string read_line(const fs::path& path)
{
......
......@@ -5,14 +5,48 @@
* BSD license as described in the LICENSE file in the top-level directory.
*/
#define BOOST_TEST_MODULE tst-vfs
#include "sched.hh"
#include "debug.hh"
#include "tst-fs.hh"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test_path_lookup)
{
TempDir dir;
BOOST_REQUIRE(fs::create_directories(dir / "sub"));
fs::path valid_paths[] = {
dir,
dir / ".",
dir / "/",
dir / "/sub",
dir / "/sub/",
dir / "/sub/",
dir / "/sub/.",
dir / "/sub/..",
dir / "/sub/../",
dir / "/sub/../sub",
dir / "/sub/../sub/",
dir / "/sub/../sub/.",
dir / "/sub/../sub/..",
dir / "/sub/../sub/../",
dir / "/sub/../sub/../sub"
};
for (auto path : valid_paths) {
BOOST_REQUIRE_MESSAGE(fs::exists(path), "Path " + path.string() + " should exist");
}
}
int main(int argc, char **argv)
BOOST_AUTO_TEST_CASE(test_concurrent_file_operations)
{
debug("Running concurrent file operation tests\n");
......@@ -23,7 +57,7 @@ int main(int argc, char **argv)
threads[i] = new sched::thread([] {
struct stat buf;
for (int j = 0; j < 1000; j++) {
assert(stat("/usr/lib/jvm/jre/lib/amd64/headless/libmawt.so", &buf)==0);
BOOST_REQUIRE(stat("/usr/lib/jvm/jre/lib/amd64/headless/libmawt.so", &buf)==0);
}
});
}
......@@ -36,5 +70,4 @@ int main(int argc, char **argv)
}
debug("concurrent file operation tests succeeded\n");
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment