Browse Source

Merge pull request #42 from trapexit/clonepath

clonepath fixes
pull/44/head
Antonio SJ Musumeci 10 years ago
parent
commit
805bc2d2e6
  1. 43
      Makefile
  2. 54
      src/clonepath.cpp
  3. 30
      src/clonepath.hpp
  4. 3
      src/create.cpp
  5. 7
      src/fs.cpp
  6. 4
      src/link.cpp
  7. 63
      src/mergerfs.cpp
  8. 3
      src/mkdir.cpp
  9. 3
      src/mknod.cpp

43
Makefile

@ -27,6 +27,7 @@ MKDIR = $(shell which mkdir)
TOUCH = $(shell which touch) TOUCH = $(shell which touch)
CP = $(shell which cp) CP = $(shell which cp)
RM = $(shell which rm) RM = $(shell which rm)
LN = $(shell which ln)
FIND = $(shell which find) FIND = $(shell which find)
INSTALL = $(shell which install) INSTALL = $(shell which install)
MKTEMP = $(shell which mktemp) MKTEMP = $(shell which mktemp)
@ -82,8 +83,8 @@ LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
BINDIR = $(PREFIX)/usr/bin BINDIR = $(PREFIX)/usr/bin
MANDIR = $(PREFIX)/usr/share/man/man1 MANDIR = $(PREFIX)/usr/share/man/man1
INSTALLTARGET = $(DESTDIR)/$(BINDIR)/$(TARGET)
MANTARGET = $(DESTDIR)/$(MANDIR)/$(MANPAGE)
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLMANDIR = $(DESTDIR)$(MANDIR)
ifeq ($(XATTR_AVAILABLE),0) ifeq ($(XATTR_AVAILABLE),0)
$(warning "xattr not available: disabling") $(warning "xattr not available: disabling")
@ -98,7 +99,7 @@ ifeq ($(KERNEL),Darwin)
CFLAGS += -DOSX CFLAGS += -DOSX
endif endif
all: $(TARGET)
all: $(TARGET) clonepath
help: help:
@echo "usage: make" @echo "usage: make"
@ -107,6 +108,9 @@ help:
$(TARGET): obj/obj-stamp $(OBJ) $(TARGET): obj/obj-stamp $(OBJ)
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS) $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
clonepath: $(TARGET)
$(LN) -s $< $@
changelog: changelog:
$(GIT) log --pretty --numstat --summary | git2cl > ChangeLog $(GIT) log --pretty --numstat --summary | git2cl > ChangeLog
@ -118,22 +122,37 @@ obj/%.o: src/%.cpp
$(CXX) $(CFLAGS) -c $< -o $@ $(CXX) $(CFLAGS) -c $< -o $@
clean: clean:
$(RM) -rf obj "$(TARGET)" "$(MANPAGE)"
$(RM) -rf obj
$(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
$(FIND) -name "*~" -delete $(FIND) -name "*~" -delete
distclean: clean distclean: clean
$(GIT) clean -fd $(GIT) clean -fd
install: $(TARGET) $(MANPAGE)
$(INSTALL) -m 0755 -D "$(TARGET)" "$(INSTALLTARGET)"
$(INSTALL) -m 0644 -D "$(MANPAGE)" "$(MANTARGET)"
install: install-base install-clonepath install-man
install-base: $(TARGET)
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
install-clonepath: clonepath
$(CP) -a $< "$(INSTALLBINDIR)/$<"
install-man: $(MANPAGE)
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMANDIR)/$(MANPAGE)"
install-strip: install-base
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
uninstall: uninstall-base uninstall-clonepath uninstall-man
uninstall-base:
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
install-strip: install
$(STRIP) "$(INSTALLTARGET)"
uninstall-clonepath:
$(RM) -f "$(INSTALLBINDIR)/clonepath"
uninstall:
$(RM) "$(INSTALLTARGET)"
$(RM) "$(MANTARGET)"
uninstall-man:
$(RM) -f "$(INSTALLMANDIR)/$(MANPAGE")
$(MANPAGE): README.md $(MANPAGE): README.md
$(PANDOC) -s -t man -o $(MANPAGE) README.md $(PANDOC) -s -t man -o $(MANPAGE) README.md

54
src/clonepath.cpp

@ -0,0 +1,54 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "fs.hpp"
namespace clonepath
{
static
void
print_usage_and__exit(void)
{
std::cerr << "usage: clonepath "
<< "<sourcedir> <destdir> <relativepath>"
<< std::endl;
_exit(1);
}
int
main(const int argc,
char * const argv[])
{
if(argc != 4)
print_usage_and__exit();
return fs::clonepath(argv[1],
argv[2],
argv[3]);
}
}

30
src/clonepath.hpp

@ -0,0 +1,30 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
namespace clonepath
{
int
main(const int argc,
char * const *argv);
}

3
src/create.cpp

@ -70,7 +70,10 @@ _create(const fs::SearchFunc searchFunc,
return -errno; return -errno;
if(createpath[0].base != existingpath[0].base) if(createpath[0].base != existingpath[0].base)
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(existingpath[0].base,createpath[0].base,dirname); fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
}
path = fs::make_path(createpath[0].base,fusepath); path = fs::make_path(createpath[0].base,fusepath);

7
src/fs.cpp

@ -424,8 +424,15 @@ namespace fs
topath = fs::make_path(tosrc,relative); topath = fs::make_path(tosrc,relative);
rv = ::mkdir(topath.c_str(),st.st_mode); rv = ::mkdir(topath.c_str(),st.st_mode);
if(rv == -1) if(rv == -1)
{
if(errno != EEXIST)
return -1; return -1;
rv = ::chmod(topath.c_str(),st.st_mode);
if(rv == -1)
return -1;
}
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid); rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
if(rv == -1) if(rv == -1)
return -1; return -1;

4
src/link.cpp

@ -73,7 +73,11 @@ _link(const fs::SearchFunc searchFunc,
fs::find::ffwp(srcmounts,todir,topaths); fs::find::ffwp(srcmounts,todir,topaths);
if(topaths.size() > 0) if(topaths.size() > 0)
{ {
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(topaths[0].base,i->base,todir); fs::clonepath(topaths[0].base,i->base,todir);
}
lrv = ::link(pathfrom.c_str(),pathto.c_str()); lrv = ::link(pathfrom.c_str(),pathto.c_str());
} }
} }

63
src/mergerfs.cpp

@ -33,6 +33,8 @@
#include "resources.hpp" #include "resources.hpp"
#include "fs.hpp" #include "fs.hpp"
#include "clonepath.hpp"
#include "access.hpp" #include "access.hpp"
#include "chmod.hpp" #include "chmod.hpp"
#include "chown.hpp" #include "chown.hpp"
@ -71,12 +73,20 @@
#include "write.hpp" #include "write.hpp"
#include "write_buf.hpp" #include "write_buf.hpp"
namespace local
{
static static
struct fuse_operations
get_fuse_operations()
std::string
getappname(const int argc,
char * const *argv)
{ {
struct fuse_operations ops = {0};
return fs::basename(argv[0]);
}
static
void
get_fuse_operations(struct fuse_operations &ops)
{
#if FLAG_NOPATH #if FLAG_NOPATH
ops.flag_nopath = false; ops.flag_nopath = false;
#endif #endif
@ -135,23 +145,38 @@ get_fuse_operations()
ops.write_buf = mergerfs::write_buf::write_buf; ops.write_buf = mergerfs::write_buf::write_buf;
#endif #endif
return ops;
return;
}
static
void
setup_resources(void)
{
std::srand(time(NULL));
mergerfs::resources::reset_umask();
mergerfs::resources::maxout_rlimit_nofile();
mergerfs::resources::maxout_rlimit_fsize();
}
} }
namespace mergerfs namespace mergerfs
{ {
int int
main(const struct fuse_args &args,
config::Config &config)
main(const int argc,
char **argv)
{ {
struct fuse_operations ops;
struct fuse_args args;
struct fuse_operations ops = {0};
mergerfs::config::Config config;
ops = get_fuse_operations();
args.argc = argc;
args.argv = argv;
args.allocated = 0;
std::srand(time(NULL));
resources::reset_umask();
resources::maxout_rlimit_nofile();
resources::maxout_rlimit_fsize();
mergerfs::options::parse(args,config);
local::setup_resources();
local::get_fuse_operations(ops);
return fuse_main(args.argc, return fuse_main(args.argc,
args.argv, args.argv,
@ -162,15 +187,13 @@ namespace mergerfs
int int
main(int argc, main(int argc,
char *argv[])
char **argv)
{ {
int rv;
mergerfs::config::Config config;
struct fuse_args args = FUSE_ARGS_INIT(argc,argv);
mergerfs::options::parse(args,config);
std::string appname;
rv = mergerfs::main(args,config);
appname = local::getappname(argc,argv);
if(appname == "clonepath")
return clonepath::main(argc,argv);
return rv;
return mergerfs::main(argc,argv);
} }

3
src/mkdir.cpp

@ -64,7 +64,10 @@ _mkdir(const fs::SearchFunc searchFunc,
rv = createPathFunc(srcmounts,dirname,createpath); rv = createPathFunc(srcmounts,dirname,createpath);
if(createpath[0].base != existingpath[0].base) if(createpath[0].base != existingpath[0].base)
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(existingpath[0].base,createpath[0].base,dirname); fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
}
path = fs::make_path(createpath[0].base,fusepath); path = fs::make_path(createpath[0].base,fusepath);

3
src/mknod.cpp

@ -66,7 +66,10 @@ _mknod(const fs::SearchFunc searchFunc,
createPathFunc(srcmounts,dirname,createpath); createPathFunc(srcmounts,dirname,createpath);
if(existingpath[0].base != createpath[0].base) if(existingpath[0].base != createpath[0].base)
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(existingpath[0].base,createpath[0].base,dirname); fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
}
path = fs::make_path(createpath[0].base,fusepath); path = fs::make_path(createpath[0].base,fusepath);

Loading…
Cancel
Save