Browse Source

Merge f283cba719 into 10a9969a64

pull/1074/merge
Matthieu Berthomé 3 years ago
committed by GitHub
parent
commit
5073ce7495
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .gitignore
  2. 4
      Makefile
  3. 16
      src/branches.cpp
  4. 62
      tests/tests.cpp
  5. 4
      tools/git2debcl

6
.gitignore

@ -15,6 +15,8 @@
# build artifacts # build artifacts
mergerfs mergerfs
obj/ obj/
*.d
build/
src/version.hpp src/version.hpp
# Debian files # Debian files
@ -23,3 +25,7 @@ debian/changelog
# RPM files # RPM files
rpmbuild/ rpmbuild/
# IDEs
\.idea/
VERSION

4
Makefile

@ -92,6 +92,10 @@ LDFLAGS := \
-pthread \ -pthread \
-lrt -lrt
ifeq ($(DEBUG),1)
LDFLAGS := ${LDFLAGS} -fsanitize=undefined
endif
DESTDIR = DESTDIR =
PREFIX = /usr/local PREFIX = /usr/local
EXEC_PREFIX = $(PREFIX) EXEC_PREFIX = $(PREFIX)

16
src/branches.cpp

@ -80,11 +80,8 @@ namespace l
uint64_t offset; uint64_t offset;
offset = s_.find_first_not_of("+<>-="); offset = s_.find_first_not_of("+<>-=");
if(offset > 1)
offset = 2;
*values_ = ((offset != std::string::npos) ? s_.substr(offset) : "");
*instr_ = s_.substr(0,offset); *instr_ = s_.substr(0,offset);
if(offset != std::string::npos)
*values_ = s_.substr(offset);
} }
static static
@ -205,6 +202,9 @@ namespace l
Branches::Impl tmp_branches(branches_->minfreespace()); Branches::Impl tmp_branches(branches_->minfreespace());
str::split(str_,':',&paths); str::split(str_,':',&paths);
if (paths.empty())
return -ENOTSUP;
for(auto &path : paths) for(auto &path : paths)
{ {
rv = l::parse(path,&tmp_branches); rv = l::parse(path,&tmp_branches);
@ -269,6 +269,9 @@ namespace l
int int
erase_begin(Branches::Impl *branches_) erase_begin(Branches::Impl *branches_)
{ {
if (branches_->size() <= 1)
return -ENOTSUP;
branches_->erase(branches_->begin()); branches_->erase(branches_->begin());
return 0; return 0;
@ -278,6 +281,9 @@ namespace l
int int
erase_end(Branches::Impl *branches_) erase_end(Branches::Impl *branches_)
{ {
if (branches_->size() <= 1)
return -ENOTSUP;
branches_->pop_back(); branches_->pop_back();
return 0; return 0;
@ -299,6 +305,8 @@ namespace l
{ {
match = ::fnmatch(pi->c_str(),i->path.c_str(),0); 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)); i = ((match == 0) ? branches_->erase(i) : (i+1));
} }

62
tests/tests.cpp

@ -115,6 +115,67 @@ test_config_branches()
TEST_CHECK(b.from_string("./foo/bar:/bar/baz:blah/asdf") == 0); 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("+</first") == 0);
TEST_CHECK(b.to_string() == "/first=RW:/second=RW");
//
TEST_CHECK(b.from_string("/first:/second") == 0);
TEST_CHECK(b.from_string("-/second") == 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() == "/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 void
test_config_cachefiles() test_config_cachefiles()
{ {
@ -274,6 +335,7 @@ TEST_LIST =
{"config_int",test_config_int}, {"config_int",test_config_int},
{"config_str",test_config_str}, {"config_str",test_config_str},
{"config_branches",test_config_branches}, {"config_branches",test_config_branches},
{"config_update_branches",test_config_update_branches},
{"config_cachefiles",test_config_cachefiles}, {"config_cachefiles",test_config_cachefiles},
{"config_inodecalc",test_config_inodecalc}, {"config_inodecalc",test_config_inodecalc},
{"config_moveonenospc",test_config_moveonenospc}, {"config_moveonenospc",test_config_moveonenospc},

4
tools/git2debcl

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> # Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
@ -19,7 +19,7 @@ import subprocess
import argparse import argparse
def call(args): 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(): def git_tags():
args = ["git", "tag", '-l'] args = ["git", "tag", '-l']

Loading…
Cancel
Save