hf_repo4 / src /core /settings.cpp
fava21's picture
Backup: patch pack applied + verified on Win11 22000 (d446cc1, ba8617e, dcf5cb8)
2edf277 verified
Raw History Blame Contribute Delete
1.75 kB
// FCS Glass - src/core/settings.cpp
//
// Implements: J8 rules 1 and 3 (the pure half). See src/core/settings.h.
#include "core/settings.h"
namespace fcs {
namespace core {
namespace {
// Index just past the last separator, or npos when the path has none. A path
// with no separator is all filename, so the "directory" is the relative case -
// which still compares equal to another bare filename, and that is correct.
std::size_t LastSeparator(const std::string& p) {
const std::size_t slash = p.find_last_of("/\\");
return slash == std::string::npos ? std::string::npos : slash + 1;
}
} // namespace
// REQ J8 - rule 1.
std::string TempPathFor(const std::string& target) { return target + ".tmp"; }
// REQ J8 - rule 1, as a checkable predicate.
bool SameDirectory(const std::string& a, const std::string& b) {
const std::size_t ia = LastSeparator(a);
const std::size_t ib = LastSeparator(b);
// npos means "no separator", i.e. the whole string is a filename. Testing
// `== 0` here instead - which is what this used to do - never matches, so two
// bare filenames fell through and compared their ENTIRE strings as if those
// were directories. T-20 caught it with "ui.json.tmp" vs "other.tmp".
const bool a_bare = (ia == std::string::npos);
const bool b_bare = (ib == std::string::npos);
// Both bare: both relative to the current directory, so the same directory.
if (a_bare && b_bare) return true;
// One bare and one absolute is not comparable, and claiming they match would
// be the exact false "same volume" answer rule 1 exists to prevent.
if (a_bare != b_bare) return false;
return a.compare(0, ia, b, 0, ib) == 0;
}
} // namespace core
} // namespace fcs