Comments (6)
@dsheets I'd be interested in your opinion on this.
Currently the function Fpath.parent
(spec, examples) always returns paths without directoryness.
This behaviour matches the implementation of POSIX dirname
--- in fact if I read well the specification it says nothing about this, but in the examples provided on that page and on my system (osx), all paths returned by dirname
except /
do not have directoryness.
Given the semantics of Fpath.parent
do you think I should rather always return paths with directoryness or .
and let the client remove the trailing slash if it whishes so using Fpath.dir_to_file
?
from fpath.
Yes, I think that is the right direction. As the parent of a path must always be a directory, I think explicitly and consistently typing this is the right semantic. I would go so far as to suggest that parent("..") = "../../"
and parent("foo/") = "./"
. I think dirname
is a bad interface as it is not consistent and understands nothing of relative path semantics.
This would give you the invariant that every path returned from parent
will end in "/". One possible catch with this design is the inability to concatenate an absolute path after the parent path but I believe that this is a feature as relative path concatenation will always work as it should. A final thing to consider is the change of referent when the parent path is a symlink. In the directoryness case, the parent paths will never be symlinks as any sane implementation will treat a trailing "/" as forcing resolution. In the other case, the dereference of a parent path could yield a symlink in the non-.
and non-/
cases. I believe the advice here should be to always use dir_to_file
to generate "node" paths to interrogate for symlink-nature.
I hope this helps.
from fpath.
Thanks for your input.
I would go so far as to suggest that parent("..") = "../../" and parent("foo/") = "./"
I guess you would then also have parent "." = "../"
.
One possible catch with this design is the inability to concatenate an absolute path after the parent path but I believe that this is a feature as relative path concatenation will always work as it should.
I don't understand this, concatenating an absolute path to another one seems like is a non-sensical operation in all cases (or in fpath
, following the design of other libraries simply returns the the absolute one) and I don't understand why you mention this in the context of parent
.
In the other case, the dereference of a parent path could yield a symlink in the non-. and non-/ cases.
What do you mean by the other case ? You mean in the current behaviour that doesn't force the final /
from fpath.
I don't understand this, concatenating an absolute path to another one seems like is a non-sensical operation in all cases (or in fpath, following the design of other libraries simply returns the the absolute one) and I don't understand why you mention this in the context of parent.
This is relevant to parent
as fpath
may be used in contexts interchangeable with shell scripting. It is common in shell scripting to do things like $PATH/continuing/the/path
which is a concatenation of an absolute path and, yes, is nonsensical. It is syntactically convenient, though, as it abuses the lexer of the script to terminate the variable identifier before /
. Consider $(dirname $PATH)/more/path
. I think that the typed, sane algebraic construction of OCaml and fpath
make this a non-issue.
What do you mean by the other case ? You mean in the current behaviour that doesn't force the final /
Yes, sorry. I mean in the dirname
case which is similar to the present behavior.
from fpath.
So I wanted to provide a function split_parent : t -> t * t
with split_parent p = (par,b)
where par
is a directory path that contains p
and b
an absolute path such that Fpath.append par b
represents the same path as p
, directoryness included (but not necessarily syntactically). The idea was then that parent
was simply fst split_parent
.
This poses two problems:
- When
p
is a root path. This can easily be solved by havingpar
beingp
itself andb
be./
. For example for the root path"/"
we then get ("/", "./"
) which appended is"/./"
which is equivalent to"/"
.par
does containp
under the view that root paths do contain themselves andb
is a relative path. So this seems correct according to the semantics given above. - Dot and dot dot only paths. This one seems unfixable. For example with
"./"
, the natural parent would be"../"
however we then can't have a value forb
without consulting the file system. Same for "../
". Once you go up with .. segments there's no way back.
So maybe split_parent
should be called split_dir
and the left hand side should simply be guaranteed to be a directory (rather than the stronger property of being a parent directory). Case 2. would then simply yield the pairs (p, "./")
like for roots. And the parent
function should be defined separately, handling .. segments as David suggested above.
from fpath.
Current master has the final design which can be reviewed here. All functions operating on paths now preserve or indicate directoryness of their results.
from fpath.
Related Issues (13)
- Add conversion to URI path HOT 1
- Bad behaviour of split_base and // with Windows paths containing colons HOT 1
- to_posix_string and to_windows_string functions HOT 1
- Question about of_string restricting result type to [`Msg] HOT 2
- Get rid of astring
- `is_prefix`, `find_prefix` and `rem_prefix` are inconsistent HOT 17
- Clarify exactly which functions do interpret .. segments. HOT 1
- Clarify empty string HOT 6
- Maybe remove Fpath.root, at least add Fpath.is_root.
- Fpath.{par_dir,cur_dir} seems not wise. HOT 1
- Clarify extension and directoryness HOT 1
- Function to check if a path has one extension in a list
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fpath.