Empty trailing path, bump version
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Armin Friedl 2021-02-21 11:17:42 +01:00
parent 6a7e98dbf6
commit 12afa628d0
Signed by: armin
GPG key ID: 48C726EEE7FBCBC8
3 changed files with 32 additions and 14 deletions

View file

@ -1,5 +1,5 @@
project('xwim', 'cpp', project('xwim', 'cpp',
version: '0.3', version: '0.4',
default_options: ['cpp_std=c++17', default_options: ['cpp_std=c++17',
'warning_level=3', 'warning_level=3',
'b_ndebug=if-release']) 'b_ndebug=if-release'])

View file

@ -18,7 +18,16 @@ fs::path archive_extension(const fs::path& path) {
// TODO: creates lots of paths, refactor // TODO: creates lots of paths, refactor
fs::path ext; fs::path ext;
fs::path tmp_ext; fs::path tmp_ext;
fs::path tmp_path = path; fs::path tmp_path;
// cater for trailing `/` which is represented
// as empty path element
for (auto p : path) {
if (!p.empty()) {
tmp_path /= p;
}
}
while (tmp_path.has_extension()) { while (tmp_path.has_extension()) {
tmp_ext = tmp_path.extension() += tmp_ext; tmp_ext = tmp_path.extension() += tmp_ext;
auto search = extensions_format.find(tmp_ext); auto search = extensions_format.find(tmp_ext);
@ -27,8 +36,8 @@ fs::path archive_extension(const fs::path& path) {
// (Combined) extension known. Remember as `ext` and keep // (Combined) extension known. Remember as `ext` and keep
// looking for even longer extensions. // looking for even longer extensions.
ext = tmp_ext; ext = tmp_ext;
} // else: (Combined) extension not known, keep `ext` as-is but try longer } // else: (Combined) extension not known, keep `ext` as-is but try
// extensions // longer extensions
tmp_path = tmp_path.stem(); tmp_path = tmp_path.stem();
} }
@ -42,10 +51,19 @@ fs::path strip_archive_extension(const fs::path& path) {
int longest_ext = 0; int longest_ext = 0;
int tmp_longest_ext = 0; int tmp_longest_ext = 0;
fs::path tmp_ext; fs::path tmp_ext;
fs::path tmp_path = path; fs::path tmp_path;
fs::path stem_path = path; fs::path stem_path;
spdlog::debug("Checking {} extensions", path); // cater for trailing `/` which is represented
// as empty path element
for(auto p: path) {
if(!p.empty()) {
tmp_path /= p;
}
}
stem_path = tmp_path;
spdlog::debug("Checking {} extensions", tmp_path);
while (tmp_path.has_extension()) { while (tmp_path.has_extension()) {
tmp_ext = tmp_path.extension() += tmp_ext; tmp_ext = tmp_path.extension() += tmp_ext;
@ -57,17 +75,18 @@ fs::path strip_archive_extension(const fs::path& path) {
// (Combined) extension known. Remember as `longest_ext` and keep // (Combined) extension known. Remember as `longest_ext` and keep
// looking for even longer extensions. // looking for even longer extensions.
longest_ext = tmp_longest_ext; longest_ext = tmp_longest_ext;
} // else: (Combined) extension not known, keep `longest_ext` as-is but try longer } // else: (Combined) extension not known, keep `longest_ext` as-is but try
// extensions // longer extensions
spdlog::debug("Stemming {} to {}", tmp_path, tmp_path.stem()); spdlog::debug("Stemming {} to {}", tmp_path, tmp_path.stem());
tmp_path = tmp_path.stem(); tmp_path = tmp_path.stem();
} }
spdlog::debug("Found {} extensions", longest_ext); spdlog::debug("Found {} extensions", longest_ext);
tmp_path = path; tmp_path = stem_path;
for(int i=0; i<longest_ext; i++) tmp_path = tmp_path.stem(); for (int i = 0; i < longest_ext; i++) tmp_path = tmp_path.stem();
spdlog::debug("Stripped path is {} ", tmp_path);
return tmp_path; return tmp_path;
} }

View file

@ -116,9 +116,8 @@ void Xwim::infer_compression_output() {
// archive name is just the name of the input with default archive // archive name is just the name of the input with default archive
// extension // extension
fs::path archive_stem = xwim::strip_archive_extension(*ins.begin()); fs::path archive_stem = xwim::strip_archive_extension(*ins.begin());
fs::path path = (*ins.begin()).stem(); archive_stem += default_extension;
path += default_extension; out = archive_stem;
out = path;
} else { } else {
// We cannot guess the name of the output archive // We cannot guess the name of the output archive