From 052d918908b4e571a42cd3fc539933f9db139e0c Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Fri, 8 Nov 2019 03:43:49 -0500 Subject: add fs.with_suffix --- docs/markdown/Fs-module.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index e68bf68..3332b1e 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -8,6 +8,8 @@ available starting with version 0.53.0. Non-absolute paths are looked up relative to the directory where the current `meson.build` file is. +If specified, `~` is expanded to the user home directory. + ### exists Takes a single string argument and returns true if an entity with that @@ -29,3 +31,16 @@ name exists on the file system. This method follows symbolic links. Takes a single string argument and returns true if the path pointed to by the string is a symbolic link. + +## Filename modification + +### with_suffix + +The `with_suffix` method allows changing the filename suffix + +```meson +original = '/opt/foo.ini' +new = fs.with_suffix('.txt') +``` + +The files need not actually exist yet for this method. \ No newline at end of file -- cgit v1.1 From 1a0b4ddf340130d270a4c96a36f915eb5b0399f3 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 10 Nov 2019 22:49:39 -0500 Subject: fs: further document and test behavior --- docs/markdown/Fs-module.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 3332b1e..7c2925f 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -36,11 +36,35 @@ by the string is a symbolic link. ### with_suffix -The `with_suffix` method allows changing the filename suffix +The `with_suffix` method is a *string manipulation* convenient for filename modifications. +It allows changing the filename suffix like: + +## swap suffix ```meson original = '/opt/foo.ini' -new = fs.with_suffix('.txt') +new = fs.with_suffix('.txt') # /opt/foo.txt +``` + +#### add suffix + +```meson +original = '/opt/foo' +new = fs.with_suffix('.txt') # /opt/foo.txt +``` + +#### compound suffix swap + +```meson +original = '/opt/foo.dll.a' +new = fs.with_suffix('.so') # /opt/foo.dll.so +``` + +#### delete suffix + +```meson +original = '/opt/foo.dll.a' +new = fs.with_suffix('') # /opt/foo.dll ``` -The files need not actually exist yet for this method. \ No newline at end of file +The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file -- cgit v1.1 From 67651271f60347b2d3cadd235a4abac0b3a1bc16 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 10 Nov 2019 23:24:02 -0500 Subject: fs: add hash compute method --- docs/markdown/Fs-module.md | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 7c2925f..499b8d2 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -32,6 +32,14 @@ name exists on the file system. This method follows symbolic links. Takes a single string argument and returns true if the path pointed to by the string is a symbolic link. +## File Parameters + +### hash + +The `hash` method computes the requested hash sum of a file. +The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. + + ## Filename modification ### with_suffix -- cgit v1.1 From a320274179ef36aa5aeb4827f777027c3ab3d785 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 10 Nov 2019 23:38:16 -0500 Subject: fs: get file size fs: add samefile --- docs/markdown/Fs-module.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 499b8d2..8ce5e32 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -36,9 +36,27 @@ by the string is a symbolic link. ### hash -The `hash` method computes the requested hash sum of a file. +The `fs.hash(filename)` method computes the requested hash sum of a file. The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. +### samefile + +The `fs.samefile(filename1, filename2)` method allows determining if two filenames refer to the same file. +Perhaps a meson.build file in one place refer to a symlink and in another place a +relative path and/or absolute path. The `samefile` method allows determining if these +are the same file. + +Examples: + +```meson +x = 'foo.txt' +y = 'sub/../foo.txt' +z = 'bar.txt' # a symlink pointing to foo.txt + +fs.samefile(x, y) # true +fs.samefile(x, z) # true +``` + ## Filename modification -- cgit v1.1 From 5db3f8ac3ddfcf8ceb92db6ce69884ad5ffaa498 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Mon, 11 Nov 2019 20:34:04 -0500 Subject: fs: correct docs --- docs/markdown/Fs-module.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 8ce5e32..423ec8e 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -69,28 +69,28 @@ It allows changing the filename suffix like: ```meson original = '/opt/foo.ini' -new = fs.with_suffix('.txt') # /opt/foo.txt +new = fs.with_suffix(original, '.txt') # /opt/foo.txt ``` #### add suffix ```meson original = '/opt/foo' -new = fs.with_suffix('.txt') # /opt/foo.txt +new = fs.with_suffix(original, '.txt') # /opt/foo.txt ``` #### compound suffix swap ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix('.so') # /opt/foo.dll.so +new = fs.with_suffix(original, '.so') # /opt/foo.dll.so ``` #### delete suffix ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix('') # /opt/foo.dll +new = fs.with_suffix(original, '') # /opt/foo.dll ``` The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file -- cgit v1.1 From 4997d93b498094248bdc0669d9515f28f7a156ef Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Mon, 11 Nov 2019 20:39:37 -0500 Subject: fs: add docs for fs.size() --- docs/markdown/Fs-module.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 423ec8e..87cbe1a 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -39,6 +39,11 @@ by the string is a symbolic link. The `fs.hash(filename)` method computes the requested hash sum of a file. The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. +### size + +The `fs.size(filename)` method returns the size of the file in bytes. +Symlinks will be resolved if possible. + ### samefile The `fs.samefile(filename1, filename2)` method allows determining if two filenames refer to the same file. -- cgit v1.1 From 2ae96f859583ed1aa1e78df73ba2895a2604fa8b Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Wed, 13 Nov 2019 00:00:15 -0500 Subject: fs: replace_suffix --- docs/markdown/Fs-module.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 87cbe1a..9a3ab10 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -8,7 +8,7 @@ available starting with version 0.53.0. Non-absolute paths are looked up relative to the directory where the current `meson.build` file is. -If specified, `~` is expanded to the user home directory. +If specified, a leading `~` is expanded to the user home directory. ### exists @@ -36,20 +36,23 @@ by the string is a symbolic link. ### hash -The `fs.hash(filename)` method computes the requested hash sum of a file. -The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512. +The `fs.hash(filename, hash_algorithm)` method returns a string containing +the hexidecimal `hash_algorithm` digest of a file. +`hash_algorithm` is a string; the available hash algorithms include: +md5, sha1, sha224, sha256, sha384, sha512. ### size -The `fs.size(filename)` method returns the size of the file in bytes. +The `fs.size(filename)` method returns the size of the file in integer bytes. Symlinks will be resolved if possible. ### samefile -The `fs.samefile(filename1, filename2)` method allows determining if two filenames refer to the same file. -Perhaps a meson.build file in one place refer to a symlink and in another place a -relative path and/or absolute path. The `samefile` method allows determining if these -are the same file. +The `fs.samefile(filename1, filename2)` returns boolean `true` if the input filenames refer to the same file. +For example, suppose filename1 is a symlink and filename2 is a relative path. +If filename1 can be resolved to a file that is the same file as filename2, then `true` is returned. +If filename1 is not resolved to be the same as filename2, `false` is returned. +If either filename does not exist, an error message is raised. Examples: @@ -65,37 +68,37 @@ fs.samefile(x, z) # true ## Filename modification -### with_suffix +### replace_suffix -The `with_suffix` method is a *string manipulation* convenient for filename modifications. +The `replace_suffix` method is a *string manipulation* convenient for filename modifications. It allows changing the filename suffix like: ## swap suffix ```meson original = '/opt/foo.ini' -new = fs.with_suffix(original, '.txt') # /opt/foo.txt +new = fs.replace_suffix(original, '.txt') # /opt/foo.txt ``` #### add suffix ```meson original = '/opt/foo' -new = fs.with_suffix(original, '.txt') # /opt/foo.txt +new = fs.replace_suffix(original, '.txt') # /opt/foo.txt ``` #### compound suffix swap ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix(original, '.so') # /opt/foo.dll.so +new = fs.replace_suffix(original, '.so') # /opt/foo.dll.so ``` #### delete suffix ```meson original = '/opt/foo.dll.a' -new = fs.with_suffix(original, '') # /opt/foo.dll +new = fs.replace_suffix(original, '') # /opt/foo.dll ``` The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file -- cgit v1.1 From 0cb48cdc793dfce8c5eeb17e447cbe169e1836d7 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 17 Nov 2019 00:22:53 -0500 Subject: fs: make replace_suffix not expand file to absolute path, just manipulate the string --- docs/markdown/Fs-module.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 9a3ab10..45cb589 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -73,7 +73,7 @@ fs.samefile(x, z) # true The `replace_suffix` method is a *string manipulation* convenient for filename modifications. It allows changing the filename suffix like: -## swap suffix +#### swap suffix ```meson original = '/opt/foo.ini' -- cgit v1.1