Skip to content

Commit 2d3ebcf

Browse files
platform: fs_caps' alias of std::filesystem is not named fs (mcpp::platform::fs is a namespace; GCC 16 crashed reading both); e2e 32, 33 link the mcpplibs index where mcpp keeps it
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent d26c235 commit 2d3ebcf

3 files changed

Lines changed: 50 additions & 45 deletions

File tree

‎modules/platform/src/fs_caps.cppm‎

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -235,38 +235,41 @@ std::string filesystem_type(const std::filesystem::path&) { return {}; }
235235

236236
namespace mcpp::platform {
237237

238-
namespace fs = std::filesystem;
238+
// Not `fs`: mcpp::platform::fs is the namespace of mcpp.platform.fs, and an
239+
// alias of the same name beside it is ill-formed (GCC 16 crashes reading the
240+
// two modules into one translation unit).
241+
namespace stdfs = std::filesystem;
239242

240-
FsCaps probe_fs_caps(const fs::path& dir) {
243+
FsCaps probe_fs_caps(const stdfs::path& dir) {
241244
FsCaps caps;
242245
caps.type = native::filesystem_type(dir);
243246
std::error_code ec;
244247
std::random_device random;
245248
const auto scratch = dir / std::format(".mcpp-fsprobe-{:08x}{:08x}", random(), random());
246-
if (!fs::create_directory(scratch, ec) || ec) return caps; // cannot write here: native answers
247-
const auto touch = [&](const fs::path& p) { std::ofstream(p).put('x'); return fs::exists(p, ec); };
249+
if (!stdfs::create_directory(scratch, ec) || ec) return caps; // cannot write here: native answers
250+
const auto touch = [&](const stdfs::path& p) { std::ofstream(p).put('x'); return stdfs::exists(p, ec); };
248251
if (touch(scratch / "a") && touch(scratch / "c")) {
249252
caps.measured = true;
250253
if (const int e = native::rename_no_replace(scratch / "a", scratch / "b"); e != 0) {
251254
caps.rename_no_replace = !native::unsupported(e);
252-
fs::rename(scratch / "a", scratch / "b", ec);
255+
stdfs::rename(scratch / "a", scratch / "b", ec);
253256
}
254257
if (const int e = native::exchange(scratch / "b", scratch / "c"); e != 0)
255258
caps.rename_exchange = !native::unsupported(e);
256259
ec.clear();
257-
fs::create_hard_link(scratch / "b", scratch / "d", ec);
260+
stdfs::create_hard_link(scratch / "b", scratch / "d", ec);
258261
caps.hard_links = !ec;
259262
ec.clear();
260-
fs::create_symlink("b", scratch / "e", ec);
263+
stdfs::create_symlink("b", scratch / "e", ec);
261264
caps.symlinks = !ec;
262265
ec.clear();
263-
if (touch(scratch / "Case")) caps.case_sensitive = !fs::exists(scratch / "cASE", ec);
266+
if (touch(scratch / "Case")) caps.case_sensitive = !stdfs::exists(scratch / "cASE", ec);
264267
}
265-
fs::remove_all(scratch, ec);
268+
stdfs::remove_all(scratch, ec);
266269
return caps;
267270
}
268271

269-
FsCaps fs_caps(const fs::path& dir) {
272+
FsCaps fs_caps(const stdfs::path& dir) {
270273
static std::mutex lock;
271274
static std::map<std::uint64_t, FsCaps> known;
272275
const auto device = native::device_of(dir);
@@ -285,7 +288,7 @@ FsCaps fs_caps(const fs::path& dir) {
285288
return caps;
286289
}
287290

288-
std::expected<void, std::string> publish_no_replace(const fs::path& from, const fs::path& to, const FsCaps& caps) {
291+
std::expected<void, std::string> publish_no_replace(const stdfs::path& from, const stdfs::path& to, const FsCaps& caps) {
289292
const auto failed = [&](std::error_code error) {
290293
return std::unexpected(std::format("cannot publish {} as {}: {}", from.string(), to.string(), error.message()));
291294
};
@@ -297,40 +300,40 @@ std::expected<void, std::string> publish_no_replace(const fs::path& from, const
297300
// the directory probed): the strategies below.
298301
}
299302
std::error_code ec;
300-
const auto status = fs::symlink_status(from, ec);
303+
const auto status = stdfs::symlink_status(from, ec);
301304
if (ec) return failed(ec);
302-
if (status.type() == fs::file_type::symlink) {
305+
if (status.type() == stdfs::file_type::symlink) {
303306
// A link made again with the same target refuses a name that is
304307
// there, as the rename flag would. (A hard link to a symbolic link is
305308
// the link on Linux but its target on macOS.)
306-
fs::copy_symlink(from, to, ec);
309+
stdfs::copy_symlink(from, to, ec);
307310
if (ec) return failed(ec);
308-
fs::remove(from, ec);
311+
stdfs::remove(from, ec);
309312
return {};
310313
}
311-
if (status.type() != fs::file_type::directory && caps.hard_links) {
312-
fs::create_hard_link(from, to, ec);
314+
if (status.type() != stdfs::file_type::directory && caps.hard_links) {
315+
stdfs::create_hard_link(from, to, ec);
313316
if (ec) return failed(ec);
314-
fs::remove(from, ec);
317+
stdfs::remove(from, ec);
315318
return {};
316319
}
317-
const auto there = fs::symlink_status(to, ec);
320+
const auto there = stdfs::symlink_status(to, ec);
318321
if (ec && ec != std::errc::no_such_file_or_directory) return failed(ec);
319-
if (fs::exists(there)) return failed(std::make_error_code(std::errc::file_exists));
320-
fs::rename(from, to, ec);
322+
if (stdfs::exists(there)) return failed(std::make_error_code(std::errc::file_exists));
323+
stdfs::rename(from, to, ec);
321324
if (ec) return failed(ec);
322325
return {};
323326
}
324327

325-
std::expected<void, std::string> rename_no_replace(const fs::path& from, const fs::path& to) {
328+
std::expected<void, std::string> rename_no_replace(const stdfs::path& from, const stdfs::path& to) {
326329
auto parent = to.parent_path();
327330
if (parent.empty()) parent = ".";
328331
return publish_no_replace(from, to, fs_caps(parent));
329332
}
330333

331-
bool create_directory_link(const fs::path& target, const fs::path& link) {
334+
bool create_directory_link(const stdfs::path& target, const stdfs::path& link) {
332335
std::error_code ec;
333-
fs::create_directory_symlink(target, link, ec);
336+
stdfs::create_directory_symlink(target, link, ec);
334337
if (!ec) return true;
335338
#if defined(_WIN32)
336339
const auto cmd = std::format("cmd /c mklink /J \"{}\" \"{}\" >nul 2>&1", link.string(), target.string());
@@ -340,13 +343,13 @@ bool create_directory_link(const fs::path& target, const fs::path& link) {
340343
#endif
341344
}
342345

343-
std::string untrusted_because(const fs::path& dir) {
346+
std::string untrusted_because(const stdfs::path& dir) {
344347
std::error_code ec;
345-
if (!fs::is_directory(dir, ec)) return "it is not a directory";
348+
if (!stdfs::is_directory(dir, ec)) return "it is not a directory";
346349
return native::owner_problem(dir);
347350
}
348351

349-
std::expected<void, std::string> exchange_paths(const fs::path& a, const fs::path& b) {
352+
std::expected<void, std::string> exchange_paths(const stdfs::path& a, const stdfs::path& b) {
350353
auto parent = b.parent_path();
351354
if (parent.empty()) parent = ".";
352355
if (fs_caps(parent).rename_exchange) {
@@ -359,15 +362,15 @@ std::expected<void, std::string> exchange_paths(const fs::path& a, const fs::pat
359362
std::error_code ec;
360363
std::random_device random;
361364
const auto aside = parent / std::format(".{}.mcpp-aside-{:08x}", b.filename().string(), random());
362-
fs::rename(b, aside, ec);
365+
stdfs::rename(b, aside, ec);
363366
if (ec) return std::unexpected(std::format("cannot move {} aside: {}", b.string(), ec.message()));
364-
fs::rename(a, b, ec);
367+
stdfs::rename(a, b, ec);
365368
if (ec) {
366369
std::error_code back;
367-
fs::rename(aside, b, back);
370+
stdfs::rename(aside, b, back);
368371
return std::unexpected(std::format("cannot move {} to {}: {}", a.string(), b.string(), ec.message()));
369372
}
370-
fs::rename(aside, a, ec);
373+
stdfs::rename(aside, a, ec);
371374
if (ec) return std::unexpected(std::format("cannot move the old {} to {}: {}", b.string(), a.string(), ec.message()));
372375
return {};
373376
}

‎tests/e2e/32_semver_merge.sh‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export MCPP_HOME="$TMP/mcpp-home"
1616
source "$(dirname "$0")/_inherit_toolchain.sh"
1717

1818
# Index is needed since we exercise version-source deps.
19-
mkdir -p "$MCPP_HOME/registry/data"
20-
# Link pre-cached index data (may be under old "mcpp-index" or new "mcpplibs" name)
21-
for idx_name in mcpplibs mcpp-index; do
22-
if [[ -d "$HOME/.mcpp/registry/data/$idx_name" ]]; then
23-
ln -sf "$HOME/.mcpp/registry/data/$idx_name" \
24-
"$MCPP_HOME/registry/data/$idx_name" 2>/dev/null \
25-
|| cp -r "$HOME/.mcpp/registry/data/$idx_name" \
26-
"$MCPP_HOME/registry/data/$idx_name"
19+
mkdir -p "$MCPP_HOME/registry/data" "$MCPP_HOME/indices"
20+
# Link the pre-cached mcpplibs index: where mcpp keeps it (indices/), or where
21+
# an earlier mcpp kept it, under the old or the new name.
22+
for src in "$HOME/.mcpp/indices/mcpplibs" "$HOME/.mcpp/registry/data/mcpplibs" "$HOME/.mcpp/registry/data/mcpp-index"; do
23+
if [[ -d "$src" ]]; then
24+
ln -sf "$src" "$MCPP_HOME/indices/mcpplibs" 2>/dev/null \
25+
|| cp -r "$src" "$MCPP_HOME/indices/mcpplibs"
26+
break
2727
fi
2828
done
2929
# Pre-cached xpkg downloads so the test doesn't re-fetch the world.

‎tests/e2e/33_multi_version_mangling.sh‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export MCPP_HOME="$TMP/mcpp-home"
2020
source "$(dirname "$0")/_inherit_toolchain.sh"
2121

2222
# Index + xpkgs need to be visible since we exercise version-source deps.
23-
mkdir -p "$MCPP_HOME/registry/data"
24-
# Link pre-cached index data (may be under old "mcpp-index" or new "mcpplibs" name)
25-
for idx_name in mcpplibs mcpp-index; do
26-
if [[ -d "$HOME/.mcpp/registry/data/$idx_name" ]]; then
27-
ln -sf "$HOME/.mcpp/registry/data/$idx_name" \
28-
"$MCPP_HOME/registry/data/$idx_name"
23+
mkdir -p "$MCPP_HOME/registry/data" "$MCPP_HOME/indices"
24+
# Link the pre-cached mcpplibs index: where mcpp keeps it (indices/), or where
25+
# an earlier mcpp kept it, under the old or the new name.
26+
for src in "$HOME/.mcpp/indices/mcpplibs" "$HOME/.mcpp/registry/data/mcpplibs" "$HOME/.mcpp/registry/data/mcpp-index"; do
27+
if [[ -d "$src" ]]; then
28+
ln -sf "$src" "$MCPP_HOME/indices/mcpplibs" 2>/dev/null \
29+
|| cp -r "$src" "$MCPP_HOME/indices/mcpplibs"
30+
break
2931
fi
3032
done
3133
if [[ -d "$HOME/.mcpp/registry/data/xpkgs" ]]; then

0 commit comments

Comments
 (0)