this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+73 -81
-10
xdg-eio/lib/xdge.ml
··· 152 152 let config_dirs t = t.config_dirs 153 153 let data_dirs t = t.data_dirs 154 154 155 - let subdir base_dir name = 156 - let path = Eio.Path.(base_dir / name) in 157 - ensure_dir path; 158 - path 159 - ;; 160 - 161 - let config_path t name = subdir t.config_dir name 162 - let data_path t name = subdir t.data_dir name 163 - let cache_path t name = subdir t.cache_dir name 164 - let state_path t name = subdir t.state_dir name 165 155 166 156 let pp ?(brief = false) ?(sources = false) ppf t = 167 157 let pp_source ppf = function
-70
xdg-eio/lib/xdge.mli
··· 250 250 @see <https://specifications.freedesktop.org/basedir-spec/latest/#variables> XDG_DATA_DIRS specification *) 251 251 val data_dirs : t -> Eio.Fs.dir_ty Eio.Path.t list 252 252 253 - (** {1 Application-specific Paths} *) 254 - 255 - (** [config_path t name] returns a path within the application's config directory. 256 - 257 - This is a convenience function that creates a subdirectory within the 258 - application's configuration directory. The subdirectory is automatically 259 - created if it doesn't exist. 260 - 261 - @param t The XDG context 262 - @param name The subdirectory name within the config directory 263 - @return Path to [{config_dir}/name] 264 - 265 - {b Example:} 266 - {[ 267 - let profiles_dir = Xdg_eio.config_path xdg "profiles" in 268 - (* Returns path to ~/.config/myapp/profiles/ *) 269 - ]} *) 270 - val config_path : t -> string -> Eio.Fs.dir_ty Eio.Path.t 271 - 272 - (** [data_path t name] returns a path within the application's data directory. 273 - 274 - This is a convenience function that creates a subdirectory within the 275 - application's data directory. The subdirectory is automatically created 276 - if it doesn't exist. 277 - 278 - @param t The XDG context 279 - @param name The subdirectory name within the data directory 280 - @return Path to [{data_dir}/name] 281 - 282 - {b Example:} 283 - {[ 284 - let db_dir = Xdg_eio.data_path xdg "databases" in 285 - (* Returns path to ~/.local/share/myapp/databases/ *) 286 - ]} *) 287 - val data_path : t -> string -> Eio.Fs.dir_ty Eio.Path.t 288 - 289 - (** [cache_path t name] returns a path within the application's cache directory. 290 - 291 - This is a convenience function that creates a subdirectory within the 292 - application's cache directory. The subdirectory is automatically created 293 - if it doesn't exist. 294 - 295 - @param t The XDG context 296 - @param name The subdirectory name within the cache directory 297 - @return Path to [{cache_dir}/name] 298 - 299 - {b Example:} 300 - {[ 301 - let thumbnails = Xdg_eio.cache_path xdg "thumbnails" in 302 - (* Returns path to ~/.cache/myapp/thumbnails/ *) 303 - ]} *) 304 - val cache_path : t -> string -> Eio.Fs.dir_ty Eio.Path.t 305 - 306 - (** [state_path t name] returns a path within the application's state directory. 307 - 308 - This is a convenience function that creates a subdirectory within the 309 - application's state directory. The subdirectory is automatically created 310 - if it doesn't exist. 311 - 312 - @param t The XDG context 313 - @param name The subdirectory name within the state directory 314 - @return Path to [{state_dir}/name] 315 - 316 - {b Example:} 317 - {[ 318 - let logs = Xdg_eio.state_path xdg "logs" in 319 - (* Returns path to ~/.local/state/myapp/logs/ *) 320 - ]} *) 321 - val state_path : t -> string -> Eio.Fs.dir_ty Eio.Path.t 322 - 323 253 (** {1 Pretty Printing} *) 324 254 325 255 (** [pp ?brief ?sources ppf t] pretty prints the XDG directory configuration.
+5 -1
xdg-eio/test/dune
··· 1 + (executable 2 + (name test_paths) 3 + (libraries xdge eio eio_main)) 4 + 1 5 (cram 2 - (deps ../example/xdg_example.exe)) 6 + (deps ../example/xdg_example.exe test_paths.exe))
+39
xdg-eio/test/test_paths.ml
··· 1 + let () = 2 + Eio_main.run @@ fun env -> 3 + let xdg = Xdge.create env#fs "path_test" in 4 + 5 + (* Test config subdirectory *) 6 + let profiles_path = Eio.Path.(Xdge.config_dir xdg / "profiles") in 7 + let profile_file = Eio.Path.(profiles_path / "default.json") in 8 + (try 9 + let content = Eio.Path.load profile_file in 10 + Printf.printf "config file content: %s" (String.trim content) 11 + with 12 + | exn -> Printf.printf "config file error: %s" (Printexc.to_string exn)); 13 + 14 + (* Test data subdirectory *) 15 + let db_path = Eio.Path.(Xdge.data_dir xdg / "databases") in 16 + let db_file = Eio.Path.(db_path / "main.db") in 17 + (try 18 + let content = Eio.Path.load db_file in 19 + Printf.printf "\ndata file content: %s" (String.trim content) 20 + with 21 + | exn -> Printf.printf "\ndata file error: %s" (Printexc.to_string exn)); 22 + 23 + (* Test cache subdirectory *) 24 + let cache_path = Eio.Path.(Xdge.cache_dir xdg / "thumbnails") in 25 + let cache_file = Eio.Path.(cache_path / "thumb1.png") in 26 + (try 27 + let content = Eio.Path.load cache_file in 28 + Printf.printf "\ncache file content: %s" (String.trim content) 29 + with 30 + | exn -> Printf.printf "\ncache file error: %s" (Printexc.to_string exn)); 31 + 32 + (* Test state subdirectory *) 33 + let logs_path = Eio.Path.(Xdge.state_dir xdg / "logs") in 34 + let log_file = Eio.Path.(logs_path / "app.log") in 35 + (try 36 + let content = Eio.Path.load log_file in 37 + Printf.printf "\nstate file content: %s\n" (String.trim content) 38 + with 39 + | exn -> Printf.printf "\nstate file error: %s\n" (Printexc.to_string exn))
+29
xdg-eio/test/xdg.t
··· 324 324 --config-dir=DIR 325 325 Override config directory. Can also be set with 326 326 327 + Test _path functions do not create directories but can access files within them: 328 + 329 + $ export HOME=/tmp/xdg_path_test 330 + $ mkdir -p /tmp/xdg_path_test 331 + $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR 332 + $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS 333 + Create config subdirectory manually and write a test file: 334 + $ mkdir -p "/tmp/xdg_path_test/.config/path_test/profiles" 335 + $ echo "test profile content" > "/tmp/xdg_path_test/.config/path_test/profiles/default.json" 336 + Create data subdirectory manually and write a test file: 337 + $ mkdir -p "/tmp/xdg_path_test/.local/share/path_test/databases" 338 + $ echo "test database content" > "/tmp/xdg_path_test/.local/share/path_test/databases/main.db" 339 + Create cache subdirectory manually and write a test file: 340 + $ mkdir -p "/tmp/xdg_path_test/.cache/path_test/thumbnails" 341 + $ echo "test cache content" > "/tmp/xdg_path_test/.cache/path_test/thumbnails/thumb1.png" 342 + Create state subdirectory manually and write a test file: 343 + $ mkdir -p "/tmp/xdg_path_test/.local/state/path_test/logs" 344 + $ echo "test log content" > "/tmp/xdg_path_test/.local/state/path_test/logs/app.log" 345 + 346 + Now test that we can read the files through the XDG _path functions: 347 + $ ./test_paths.exe 348 + config file content: test profile content 349 + data file content: test database content 350 + cache file content: test cache content 351 + state file content: test log content 352 + 353 + This test verifies that the _path functions return correct paths that can be used to access 354 + files within XDG subdirectories, without the functions automatically creating those directories. 355 +