Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.4.8

- **A link's own stamp (`fs::stamp_of(node, false)`).** With `resolve` false
the stamp is the link's own size and modification time, read without
following it (openkal's `KAL_FS_NO_RESOLVE`), and a dangling link has one. A
program that keeps links as records reads them so: a store's roots, whose
time is when their owner last used the payload they name (xlings'
store-roots specification). The default is unchanged.

## 0.4.7

- **The processor's model (`machine::processor_model`).** The model as the
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ at a time). `windows::console_text_code_page()` and
| `mcpplibs.os.platform` | `PLATFORM`, `ARCH`, `is_linux` / `is_macos` / `is_windows` / `is_posix` / `is_openkal` / `is_emscripten`, `exe_suffix`, `path_list_separator`; `host()`, a constant expression on a native target; `can_run_on(p)` and `on<P>(f)`, a platform question that holds in a native build and an image alike |
| `mcpplibs.os.error` | `errc` (openkal's closed set of conditions), `error`, `result<T>` |
| `mcpplibs.os.env` | variables (names without case on Windows), `NAME=value` entries as overrides (`assignments`), arguments, the program's own image, lists of directories in the host's separator (`split_list`, `join_list`), PATH search with PATHEXT, the kernel layer's version (`kernel_layer`) |
| `mcpplibs.os.fs` | `write_atomic`, `publish` (no replace), `append`, `sync`, `caps`, `lock`, links, `set_executable`, `stamp_of`, `identity_of`, `owner_of`, `writable`, `locate`, `absolute`, `names_a_place`, `canonical`, a bounded `read`; what a volume does, measured (`measure`, `volume_type`), and the operations that follow it (`place`, `exchange`); names in the host's rules without the file system: `generic`, `native`, `extended`, `is_absolute`, `same`, `within`; which names changed (`watcher`: inotify, kqueue, `ReadDirectoryChangesW`; a look when asked in an image and on Emscripten) |
| `mcpplibs.os.fs` | `write_atomic`, `publish` (no replace), `append`, `sync`, `caps`, `lock`, links, `set_executable`, `stamp_of` (of a node, or of a link itself), `identity_of`, `owner_of`, `writable`, `locate`, `absolute`, `names_a_place`, `canonical`, a bounded `read`; what a volume does, measured (`measure`, `volume_type`), and the operations that follow it (`place`, `exchange`); names in the host's rules without the file system: `generic`, `native`, `extended`, `is_absolute`, `same`, `within`; which names changed (`watcher`: inotify, kqueue, `ReadDirectoryChangesW`; a look when asked in an image and on Emscripten) |
| `mcpplibs.os.process` | `spawn`, `run` (and with bounds: a hard bound, a grace, a drain, output limits), `exec`, a command line joined as it is for the command interpreter (`one_string`), pipes, both outputs on one pipe, output onto this program's error output, units and `end_unit`, declared units, observation and retirement, bound lifetime, bounded waits and reads; `self`, `describe`, `alive`, `threads` |
| `mcpplibs.os.interrupt` | `requested`, `wait`, `end_as_requested`, `end_as_output_closed` |
| `mcpplibs.os.stdio` | the three streams as bytes; a bounded read of input; the output sent to the error stream for a while (`output_to_error`); what a stream is written, kept and taken in parts (`capture`) |
Expand Down
2 changes: 1 addition & 1 deletion mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "os"
version = "0.4.7"
version = "0.4.8"
description = "mcpplibs.os: a C++ operating-system library over openkal --- processes, files, environment, terminals, directories and local IPC, with compile-time platform constants and a few platform modules."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down
10 changes: 6 additions & 4 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,24 +474,26 @@ result<void> set_executable(const std::filesystem::path& file, bool executable)
}

namespace {
result<kal_node_info> info(const std::filesystem::path& node, kal_u32 wanted, std::string_view doing) {
result<kal_node_info> info(const std::filesystem::path& node, kal_u32 wanted, std::string_view doing,
kal_uintptr flags = 0) {
auto l = where(node, doing);
if (!l) return std::unexpected(l.error());
kal_node_info i{};
i.self_size = sizeof i;
// The kind is asked for as well, because absence is read from it: an
// implementation fills only the fields it was asked for (openkal-emscripten
// does), and a kind left at zero reads as kal_node_absent.
const int rc = kal_fs_info(dir_of(*l), l->relative.data(), l->relative.size(), 0,
const int rc = kal_fs_info(dir_of(*l), l->relative.data(), l->relative.size(), flags,
wanted | kal::fs::field::kind, &i);
if (rc != kal_ok) return std::unexpected(from_kal(rc, std::format("{} {}", doing, generic_utf8(node))));
if (i.kind == kal_node_absent) return std::unexpected(error{ errc::not_found, std::format("{} {}", doing, generic_utf8(node)) });
return i;
}
} // namespace

result<stamp> stamp_of(const std::filesystem::path& node) {
auto i = info(node, kal::fs::field::size | kal::fs::field::modified, "asking about");
result<stamp> stamp_of(const std::filesystem::path& node, bool resolve) {
auto i = info(node, kal::fs::field::size | kal::fs::field::modified, "asking about",
resolve ? 0 : kal::fs::no_resolve);
if (!i) return std::unexpected(i.error());
return stamp{ i->size, i->modified_ns };
}
Expand Down
7 changes: 6 additions & 1 deletion src/fs.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ struct stamp {
std::uint64_t modified_ns = 0;
auto operator<=>(const stamp&) const = default;
};
result<stamp> stamp_of(const std::filesystem::path& node);
// `resolve' false: the stamp of the name itself where it is a link --- the
// link's own size and modification time --- and not of the node it finally
// refers to. A program that keeps links as records (a store's roots, whose
// time is when their owner last used the payload) reads them so; a dangling
// link has a stamp of its own.
result<stamp> stamp_of(const std::filesystem::path& node, bool resolve = true);

// Two names are one node exactly when their identities are equal.
struct identity {
Expand Down
6 changes: 6 additions & 0 deletions tests/fs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ UTest fs_tests{"fs", [] {
expect(t && t->find("target") != std::string::npos) << "and reads back its target";
expect(stdfs::exists(dir / "link" / ".")) << "and reaches the directory";
}
// A link's own stamp: one that names nothing has one, and what it
// would finally refer to has none.
if (os::fs::create_link("nowhere", dir / "dangling", false)) {
expect(os::fs::stamp_of(dir / "dangling", false).has_value()) << "a dangling link has a stamp of its own";
expect(!os::fs::stamp_of(dir / "dangling").has_value()) << "and what it refers to has none";
}
}
if (!caps || caps->rename_no_replace) {
expect(os::fs::rename(file, dir / "b.txt", false).has_value()) << "a rename that does not replace renames to a free name";
Expand Down
Loading