From d1f3bd82e82d7c5dc7c7059f93de7baa0ea18587 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Tue, 27 Jan 2015 18:25:20 -0500 Subject: [PATCH] add clonepath tool --- Makefile | 43 ++++++++++++++++++++++++++----------- src/clonepath.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/clonepath.hpp | 30 ++++++++++++++++++++++++++ src/mergerfs.cpp | 18 +++++++++++++--- 4 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 src/clonepath.cpp create mode 100644 src/clonepath.hpp diff --git a/Makefile b/Makefile index 83f33382..f5219e07 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ MKDIR = $(shell which mkdir) TOUCH = $(shell which touch) CP = $(shell which cp) RM = $(shell which rm) +LN = $(shell which ln) FIND = $(shell which find) INSTALL = $(shell which install) MKTEMP = $(shell which mktemp) @@ -82,8 +83,8 @@ LDFLAGS = $(shell $(PKGCONFIG) fuse --libs) BINDIR = $(PREFIX)/usr/bin MANDIR = $(PREFIX)/usr/share/man/man1 -INSTALLTARGET = $(DESTDIR)/$(BINDIR)/$(TARGET) -MANTARGET = $(DESTDIR)/$(MANDIR)/$(MANPAGE) +INSTALLBINDIR = $(DESTDIR)$(BINDIR) +INSTALLMANDIR = $(DESTDIR)$(MANDIR) ifeq ($(XATTR_AVAILABLE),0) $(warning "xattr not available: disabling") @@ -98,7 +99,7 @@ ifeq ($(KERNEL),Darwin) CFLAGS += -DOSX endif -all: $(TARGET) +all: $(TARGET) clonepath help: @echo "usage: make" @@ -107,6 +108,9 @@ help: $(TARGET): obj/obj-stamp $(OBJ) $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS) +clonepath: $(TARGET) + $(LN) -s $< $@ + changelog: $(GIT) log --pretty --numstat --summary | git2cl > ChangeLog @@ -118,22 +122,37 @@ obj/%.o: src/%.cpp $(CXX) $(CFLAGS) -c $< -o $@ clean: - $(RM) -rf obj "$(TARGET)" "$(MANPAGE)" + $(RM) -rf obj + $(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath $(FIND) -name "*~" -delete distclean: clean $(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 $(PANDOC) -s -t man -o $(MANPAGE) README.md diff --git a/src/clonepath.cpp b/src/clonepath.cpp new file mode 100644 index 00000000..c8ef9aee --- /dev/null +++ b/src/clonepath.cpp @@ -0,0 +1,54 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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 + +#include + +#include "fs.hpp" + +namespace clonepath +{ + static + void + print_usage_and__exit(void) + { + std::cerr << "usage: clonepath " + << " " + << 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]); + } +} diff --git a/src/clonepath.hpp b/src/clonepath.hpp new file mode 100644 index 00000000..07a80d31 --- /dev/null +++ b/src/clonepath.hpp @@ -0,0 +1,30 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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); +} diff --git a/src/mergerfs.cpp b/src/mergerfs.cpp index d4e01693..1f35f95e 100644 --- a/src/mergerfs.cpp +++ b/src/mergerfs.cpp @@ -33,6 +33,8 @@ #include "resources.hpp" #include "fs.hpp" +#include "clonepath.hpp" + #include "access.hpp" #include "chmod.hpp" #include "chown.hpp" @@ -73,6 +75,14 @@ namespace local { + static + std::string + getappname(const int argc, + char * const *argv) + { + return fs::basename(argv[0]); + } + static void get_fuse_operations(struct fuse_operations &ops) @@ -179,9 +189,11 @@ int main(int argc, char **argv) { - int rv; + std::string appname; - rv = mergerfs::main(argc,argv); + appname = local::getappname(argc,argv); + if(appname == "clonepath") + return clonepath::main(argc,argv); - return rv; + return mergerfs::main(argc,argv); }