diff --git a/.gitignore b/.gitignore index 7a510743f..e1924aeb6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ # build artifacts mergerfs obj/ +*.d +build/ src/version.hpp # Debian files @@ -23,3 +25,7 @@ debian/changelog # RPM files rpmbuild/ + +# IDEs +\.idea/ +VERSION diff --git a/Makefile b/Makefile index cd614eecc..bc4327cb0 100644 --- a/Makefile +++ b/Makefile @@ -93,6 +93,10 @@ LDFLAGS := \ -pthread \ -lrt +ifeq ($(DEBUG),1) +LDFLAGS := ${LDFLAGS} -fsanitize=undefined +endif + DESTDIR = PREFIX = /usr/local EXEC_PREFIX = $(PREFIX) diff --git a/src/branches.cpp b/src/branches.cpp index 99a0eaf88..d5a57e3df 100644 --- a/src/branches.cpp +++ b/src/branches.cpp @@ -80,11 +80,8 @@ namespace l uint64_t offset; offset = s_.find_first_not_of("+<>-="); - if(offset > 1) - offset = 2; + *values_ = ((offset != std::string::npos) ? s_.substr(offset) : ""); *instr_ = s_.substr(0,offset); - if(offset != std::string::npos) - *values_ = s_.substr(offset); } static @@ -205,6 +202,9 @@ namespace l Branches::Impl tmp_branches(branches_->minfreespace()); str::split(str_,':',&paths); + if (paths.empty()) + return -ENOTSUP; + for(auto &path : paths) { rv = l::parse(path,&tmp_branches); @@ -269,6 +269,9 @@ namespace l int erase_begin(Branches::Impl *branches_) { + if (branches_->size() <= 1) + return -ENOTSUP; + branches_->erase(branches_->begin()); return 0; @@ -278,6 +281,9 @@ namespace l int erase_end(Branches::Impl *branches_) { + if (branches_->size() <= 1) + return -ENOTSUP; + branches_->pop_back(); return 0; @@ -299,6 +305,8 @@ namespace l { match = ::fnmatch(pi->c_str(),i->path.c_str(),0); } + if (match == 0 && branches_->size() == 1) + return -ENOTSUP; i = ((match == 0) ? branches_->erase(i) : (i+1)); } diff --git a/tests/tests.cpp b/tests/tests.cpp index 3c9716762..1a667f553 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -115,6 +115,67 @@ test_config_branches() TEST_CHECK(b.from_string("./foo/bar:/bar/baz:blah/asdf") == 0); } + +void +test_config_update_branches() +{ + uint64_t minfreespace; + Branches b(minfreespace); + + minfreespace = 1234; + + // + TEST_CHECK(b.from_string("/first:/second") == 0); + + TEST_CHECK(b.from_string("-/first") == 0); + TEST_CHECK(b.to_string() == "/second=RW"); + + TEST_CHECK(b.from_string("+>/last") == 0); + TEST_CHECK(b.to_string() == "/second=RW:/last=RW"); + + TEST_CHECK(b.from_string("+/last") == 0); + TEST_CHECK(b.to_string() == "/second=RW:/last=RW:/last=RW"); + + // + TEST_CHECK(b.from_string("/second") == 0); + + TEST_CHECK(b.from_string("+") == 0); + TEST_CHECK(b.to_string() == "/first=RW"); + + // + TEST_CHECK(b.from_string("/first:/second") == 0); + + TEST_CHECK(b.from_string("-<") == 0); + TEST_CHECK(b.to_string() == "/second=RW"); + + // + TEST_CHECK(b.from_string("=/dir") == 0); + TEST_CHECK(b.to_string() == "/dir=RW"); + TEST_CHECK(b.from_string("/dir") == 0); + TEST_CHECK(b.to_string() == "/dir=RW"); + + // error out when no branches left + TEST_CHECK(b.from_string("=/dir") == 0); + TEST_CHECK(b.from_string("-/dir") < 0); + TEST_CHECK(b.from_string("-<") < 0); + TEST_CHECK(b.from_string("->") < 0); + + // error out when setting empty branches + TEST_CHECK(b.from_string("=") < 0); + TEST_CHECK(b.from_string("") < 0); +} + void test_config_cachefiles() { @@ -274,6 +335,7 @@ TEST_LIST = {"config_int",test_config_int}, {"config_str",test_config_str}, {"config_branches",test_config_branches}, + {"config_update_branches",test_config_update_branches}, {"config_cachefiles",test_config_cachefiles}, {"config_inodecalc",test_config_inodecalc}, {"config_moveonenospc",test_config_moveonenospc}, diff --git a/tools/git2debcl b/tools/git2debcl index 8d0423ce8..69ed69c8b 100755 --- a/tools/git2debcl +++ b/tools/git2debcl @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright (c) 2016, Antonio SJ Musumeci @@ -19,7 +19,7 @@ import subprocess import argparse def call(args): - return subprocess.Popen(args,stdout=subprocess.PIPE).communicate()[0].decode() + return subprocess.Popen(args,stdout=subprocess.PIPE).communicate()[0].decode('utf-8') def git_tags(): args = ["git", "tag", '-l']