Skip to content

Commit

Permalink
resolve absolute file paths on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
hirthwork committed Sep 24, 2016
1 parent 90d80bb commit 67e4be4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ $(testdir)/basic-listing/run:
test "$$(/bin/echo -e 'dir1\ndir2\nfile2\nfile3\nfile4'; \
/bin/echo -e 'multi w\\rd\nsubdir1\ntag2\ntag3')" = \
"$$(ls $(dir $@)mount/tag1)"
# repeat same tests with default min-files and single thread
# run same tests with default min-files, single thread and relative dir
fusermount -z -u $(dir $@)mount
$(target) -d $(abspath $(dir $@)data) -- -s $(dir $@)mount
$(target) -d $(dir $@)data -- -s $(dir $@)mount
test "$$(/bin/echo -e 'file1.xml\nfile2\nfile3\nfile4')" = \
"$$(ls $(dir $@)mount)"
test "$$(/bin/echo -e 'file1.xml\nfile2\nfile4')" = \
Expand All @@ -118,33 +118,32 @@ $(testdir)/errors/run:
setfattr -n user.xynta.tags -v tag2 $(dir $@)data/file2
# create file/tag name collision
/bin/echo "file3 content" > $(dir $@)data/tag1
echo '! $(target) -d $(abspath $(dir $@)data) -m0 -- $(dir $@)mount' \
| sh
echo '! $(target) -d $(dir $@)data -m0 -- $(dir $@)mount' | sh
rm $(dir $@)data/tag1
# create file/tag self collision
/bin/echo "file4 content" > $(dir $@)data/file4
setfattr -n user.xynta.tags -v file4 $(dir $@)data/file4
echo '! $(target) -d $(abspath $(dir $@)data) -m0 -- $(dir $@)mount' \
| sh
echo '! $(target) -d $(dir $@)data -m0 -- $(dir $@)mount' | sh
rm $(dir $@)data/file4
# create file names collision
mkdir $(dir $@)data/dir
/bin/echo "file5 content" > $(dir $@)data/dir/file1
echo '! $(target) -d $(abspath $(dir $@)data) -m0 -- $(dir $@)mount' \
| sh
echo '! $(target) -d $(dir $@)data -m0 -- $(dir $@)mount' | sh
rm -r $(dir $@)data/dir
# create broken symlink
ln -s nowhere-is-here $(dir $@)data/file6
echo '! $(target) -d $(dir $@)data -m0 -- $(dir $@)mount' | sh
rm $(dir $@)data/file6
# try load data from non-existing dir
echo '! $(target) -d $(abspath $(dir $@)ndata) -m0 -- $(dir $@)mount' \
| sh
echo '! $(target) -d $(dir $@)ndata -m0 -- $(dir $@)mount' | sh
# pass invalid option
echo '! $(target) -d $(abspath $(dir $@)ndata) -X -- $(dir $@)mount' \
| sh
echo '! $(target) -d $(dir $@)data -X -- $(dir $@)mount' | sh
# request help
$(target) -h
# `forget' to pass data dir
echo '! $(target) -- $(dir $@)mount' | sh
# ok, test runtime errors on invalid paths
$(target) -d $(abspath $(dir $@)data) -m0 -- $(dir $@)mount
$(target) -d $(dir $@)data -m0 -- $(dir $@)mount
test ! -d $(dir $@)mount/tag1/tag2
test ! -f $(dir $@)mount/tag1/file2
test ! -e $(dir $@)mount/something
Expand Down
8 changes: 7 additions & 1 deletion src/fs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <dirent.h>
#include <fuse_lowlevel.h>
#include <stdlib.h> // realpath, free
#include <sys/stat.h>
#include <sys/types.h> // DIR
#include <sys/xattr.h> // getxattr
Expand Down Expand Up @@ -62,7 +63,12 @@ void xynta::fs::process_dir(
if (*dirent->d_name != '.') {
auto current_tags = tags;
std::string name{dirent->d_name};
auto path = root + name;
char* fullpath = realpath((root + name).c_str(), nullptr);
if (!fullpath) {
throw std::system_error(errno, std::system_category());
}
std::string path{fullpath};
free(fullpath);
struct stat stat;
if (::stat(path.c_str(), &stat)) {
throw std::system_error(errno, std::system_category());
Expand Down

0 comments on commit 67e4be4

Please sign in to comment.