-
Notifications
You must be signed in to change notification settings - Fork 72
Improvements to the System library #1735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cgay
wants to merge
9
commits into
dylan-lang:master
Choose a base branch
from
cgay:system
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2cb58ba
system: Improve resolve-locator and directory-contents
cgay 8dc92d0
package: Update deft dependency to v0.13
cgay 3d26ff5
system: Replace resolve-locator:locators with resolve-file:file-system
cgay a89d0f1
system: Cleanup == instead of =, fix comments
cgay 138105a
system: Improve expand-pathname
cgay a76e8d7
system: Use getpwnam_r on Unix platforms
cgay c29f640
system: Remove obfuscation from dump-magic-numbers.c
cgay 31a6028
system: Use getpwuid_r for file-property(file, #"author")
cgay 048e1b9
system: Fix infinite loop in link-target (on Unix)
cgay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,8 @@ properties of the file. | |
- :func:`file-properties` | ||
- :func:`file-property` | ||
- :func:`file-type` | ||
- :func:`link-target` | ||
- :gf:`link-target` | ||
- :gf:`resolve-file` | ||
|
||
File system locators | ||
-------------------- | ||
|
@@ -646,16 +647,26 @@ File-System module. | |
|
||
Returns a sequence of files and subdirectories contained in a directory. | ||
|
||
:signature: directory-contents *directory* => *locators* | ||
:signature: directory-contents *directory* #key *resolve-links?* => *locators* | ||
|
||
:parameter directory: An instance of :type:`<pathname>`. | ||
:parameter #key resolve-links?: An instance of :drm:`<boolean>`. The default is :drm:`#f`. | ||
:value locators: A :drm:`<sequence>` of :class:`<locator>`. | ||
|
||
:description: | ||
|
||
In the result, each file is represented by a :class:`<file-locator>` and | ||
each directory is represented by a :class:`<directory-locator>`. The "." | ||
and ".." directories are not included in the result. | ||
Returns a sequence of locators describing the files contained in *directory*. The | ||
"." and ".." directories are not included in the result. | ||
|
||
If *resolve-links?* is false then symbolic links are returned as instances of | ||
:class:`<file-locator>`. If true, then symbolic links are resolved and the correct | ||
class of locator, :class:`<file-locator>` or :class:`<directory-locator>`, is | ||
determined based on the file type of the (fully resolved) link target. | ||
|
||
Note that if a symlink points to another file in *directory* then the resulting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use "symbolic link" consistently rather than the colloquial "symlink". |
||
sequence may contain duplicates (in the sense of naming the same file system | ||
entity, not in the sense of Dylan object equality) when *resolve-links?* is | ||
true. | ||
|
||
.. generic-function:: directory-empty? | ||
|
||
|
@@ -758,26 +769,27 @@ File-System module. | |
|
||
.. generic-function:: expand-pathname | ||
|
||
Given a pathname, returns its fully expanded form. | ||
|
||
:signature: expand-pathname *path* => *expanded-path* | ||
|
||
:param path: An instance of :class:`<pathname>`. | ||
:value expanded-path: An instance of :class:`<pathname>`. | ||
Replaces an initial pathname component of ``~`` or ``~user`` with that user's home | ||
directory. | ||
|
||
.. method:: expand-pathname | ||
:specializer: <file-system-locator> | ||
:signature: expand-pathname *pathname* => *locator* | ||
|
||
Expand a file path to its fully expanded form. | ||
:param path: An instance of :type:`<pathname>`. | ||
:value expanded: An instance of :class:`<locator>`. | ||
|
||
:param path: An instance of :class:`<file-system-locator>`. | ||
:description: | ||
|
||
.. method:: expand-pathname | ||
:specializer: <string> | ||
.. note:: On Windows only ``~`` is replaced; expansion of ``~user`` is not yet | ||
implemented. | ||
|
||
Expands a pathname given as a string. | ||
If *pathname* is an instance of :drm:`<string>` it is first converted to a | ||
:class:`<file-system-locator>`. If the first component of this locator begins with | ||
`~` it is replaced by either the specified user's home directory (for ``~user``) or | ||
the current user's home directory (for ``~``). Otherwise the locator is returned | ||
unmodified. | ||
|
||
:param path: An instance of :class:`<string>`. | ||
If the specified ``~user`` doesn't exist no error is signaled and the locator is | ||
returned without expansion being performed. | ||
|
||
.. generic-function:: file-error-locator | ||
|
||
|
@@ -841,7 +853,7 @@ File-System module. | |
:signature: file-exists? *file* #key *follow-links?* => *exists?* | ||
|
||
:parameter file: An instance of :type:`<pathname>`. | ||
:parameter follow-links?: An instance of :drm:`<boolean>`. Defaults to | ||
:parameter #key follow-links?: An instance of :drm:`<boolean>`. Defaults to | ||
:drm:`#t`. | ||
:value exists?: An instance of :drm:`<boolean>`. | ||
|
||
|
@@ -1059,6 +1071,9 @@ File-System module. | |
file system entity can either be a file, a directory, or a link to | ||
another file or directory. | ||
|
||
This function does not resolve symbolic links. To find the file type of the link | ||
target call :gf:`link-target` or :gf:`resolve-file` on *file* first. | ||
|
||
.. type:: <file-type> | ||
|
||
The type representing all possible types of a file system entity. | ||
|
@@ -1105,21 +1120,60 @@ File-System module. | |
permissions set on the file are incorrect or insufficient for | ||
your operation. | ||
|
||
.. function:: link-target | ||
.. generic-function:: link-target | ||
|
||
Returns the target of a symbolic link. | ||
|
||
:signature: link-target *file* => *target* | ||
.. note:: On Windows this function is not implemented; it always signals an error. | ||
|
||
:signature: link-target *file* #key *follow-links?* => *target* | ||
:parameter file: An instance of type :type:`<pathname>`. | ||
:value target: An instance of type :type:`<pathname>`. | ||
:parameter #key follow-links?: An instance of type :drm:`<boolean>`. The default is | ||
:drm:`#t`. | ||
:value target: :drm:`#f` or an instance of type :class:`<file-system-locator>`. | ||
:description: | ||
|
||
Repeatedly follows symbolic links starting with *file* until it finds a | ||
non-link file or directory, or a non-existent link target. | ||
Returns a locator identifying the target of symbolic link *file*. | ||
|
||
Signals :class:`<file-system-error>` if the system call to read the link target | ||
fails for any reason. For example, if *file* is not a symbolic link or if *file* | ||
does not exist. | ||
|
||
If ``follow-links?`` is true (the default) then links are followed until a file | ||
that is not a symbolic link is found, and the locator for that file is returned. If | ||
the final link in a chain of one or more symbolic links points to a non-existent | ||
file, :drm:`#f` is returned. | ||
|
||
If ``follow-links?`` is false, no attempt is made to follow the link or to check | ||
whether the link target file exists. A locator representing the target is | ||
returned. | ||
|
||
:seealso: | ||
|
||
- :func:`create-symbolic-link` | ||
- :gf:`resolve-file` | ||
|
||
.. generic-function:: resolve-file | ||
:open: | ||
|
||
Resolves a file path to its simplest representation containing no symbolic links. | ||
|
||
:signature: resolve-file *path* => *resolved-path* | ||
|
||
:description: | ||
|
||
Resolves all links, parent references (``..``), self references (``.``), and | ||
removes unnecessary path separators. Similar to :func:`simplify-locator` except | ||
that it consults the file system to resolve links. A :class:`<file-system-error>` | ||
is signaled if for any reason the path can't be resolved. Examples include | ||
non-existent directory components, access denied, I/O error, etc. In short, this | ||
function follows the semantics of POSIX ``realpath(3)``. | ||
|
||
:parameter path: An instance of :type:`<pathname>`. | ||
:value resolved-path: An instance of :class:`<file-system-locator>`. More | ||
specifically, the return value will be an instance of :class:`<file-locator>` or | ||
:class:`<directory-locator>` depending on the type of the resolved file system | ||
entity. | ||
|
||
.. _make: | ||
|
||
|
@@ -1276,7 +1330,7 @@ File-System module. | |
- :func:`file-property-setter` | ||
- :func:`file-type` | ||
- :func:`home-directory` | ||
- :func:`link-target` | ||
- :gf:`link-target` | ||
- :func:`rename-file` | ||
- :func:`create-symbolic-link` | ||
|
||
|
@@ -1315,7 +1369,7 @@ File-System module. | |
|
||
:parameter old-file: An instance of :type:`<pathname>`. | ||
:parameter new-file: An instance of :type:`<pathname>`. | ||
:parameter if-exists: An instance of | ||
:parameter #key if-exists: An instance of | ||
:type:`<copy/rename-disposition>`. Default value: ``#"signal"``. | ||
|
||
:description: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"dependencies": [ | ||
"[email protected]", | ||
"[email protected]", | ||
"deft@0.12", | ||
"deft@0.13", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the
:file:
role for these