fgof-state Public
Go to file
T
Code
Use Git or checkout with SVN using the web URL.
No matching headings.
fgof-state
Persistent app and workspace state helpers for modern Fortran.
fgof-state is intended to be a small, standalone library for durable local
state, atomic save flows, and version-aware app data that CLI tools and
interactive apps keep hand-rolling.
It is part of the FortranGoingOnForty lib-modules
catalog, but it is intended to stand on its own as a normal fpm package.
Current v1 target:
- stable state option, root, and document types
- predictable state-root resolution from explicit paths or XDG defaults
- atomic save or replace semantics for app and workspace state
- simple version-aware load or save flows with room for migrations later
Future scope:
- richer schema migration helpers
- backup or recovery helpers for state upgrades
- higher-level workspace and session persistence flows
Status
Sprint 04 is in place.
Tracked today:
- explicit state-root resolution from
root_dir,XDG_STATE_HOME, orHOME - namespace and scope-aware root layout
- document-path helpers and document resolution
- text-focused state save, load, and remove helpers
fgof-temp-backed atomic replace semantics for saves- side-effect-free reads and removes when state roots are missing
- version-aware state envelopes with explicit mismatch handling
- explicit
version_checked/version_matchedresult semantics for version-aware loads - malformed or unsupported state payloads rejected as version errors
- unreadable state files reported as
iofailures - invalid version arguments rejected before filesystem writes
- tracked round-trip and version-mismatch examples
- POSIX root creation and existence checks
- focused scaffold coverage in
fpm test - CI on macOS and Ubuntu, including direct example execution
Why Use It
- app and workspace state shows up everywhere once tools grow past trivial size
- atomic persistence is easy to get subtly wrong
- a focused state layer builds naturally on the released temp and cache modules
Public API Shape
Primary modules:
fgof_statefgof_state_types
Public types:
state_optionsstate_rootstate_documentstate_text_result
Public constants:
FGOF_STATE_OKFGOF_STATE_ERR_INVALID_OPTIONSFGOF_STATE_ERR_NOT_FOUNDFGOF_STATE_ERR_IOFGOF_STATE_ERR_VERSIONFGOF_STATE_ERR_INTERNAL
Current public procedures:
clear_state_optionsclear_state_rootclear_state_documentclear_state_text_resultensure_state_rootsave_state_textload_state_textremove_state_documentstate_relative_path_for_namestate_path_for_nameresolve_state_documentstate_backend_namestate_error_name
Current semantics:
ensure_state_root()resolves from explicitroot_dir, or fromXDG_STATE_HOME/HOMEwhenroot_diris absent- explicit
namespaceandscopevalues extend the resolved root path as validated path segments create_root=.true.creates state directories on demand;create_root=.false.requires the root to already existstate_relative_path_for_name()andstate_path_for_name()expose the stable document path shape for valid document namesresolve_state_document()returns the resolved root path, relative path, full path, and current presence state for a state documentsave_state_text()writes exact Fortran character payloads with same-directory atomic replacement throughfgof-tempload_state_text()reads stored text back without creating missing roots as a side effectremove_state_document()removes stored state files without creating missing roots as a side effectsave_state_text()stores a small internal format header plus a positive document version; the default version is1load_state_text()surfaces the stored version onstate_text_result%document%versionstate_text_result%version_checkedtells callers whetherexpected_version=was actually applied for that loadload_state_text(..., expected_version=...)reportsversionerrors explicitly when the stored document version does not match the caller expectationstate_text_result%version_matchedis only meaningful whenstate_text_result%version_checkedis.true.- unsupported or malformed state payloads also report
versionerrors instead of pretending to be valid text - unreadable state files report
ioerrors during load - missing documents report
not-foundfor load or remove flows - document names, namespaces, and scopes must not be empty, contain
/, or be./..
Build And Test
fpm test
That is the baseline verification command locally and in CI.
Tracked examples:
Supported Platforms
- macOS
- Linux
Boundaries
- intended to stay independently versioned and releasable
- focused on state ergonomics, not full database or cache policy management
- should stay useful on its own even if future higher-level app packages build on top
License
MIT