It would be good to have "canonicalize" operation, where we can know the actual absolute path to a file without any '.' and '..'
There are two methods,
String manipulation
for example, converting /welcome/../file, we will get /file.
But this is not preferred, as something like this /folder/file/../file2 will become /folder/file2, which doesn't make sense, as file is a file, and doesn't have .. inside it.
Treversing
The other method is to build the path while treversing, we will keep a PathBuf, and append to it when we go to a new folder, and pop when we go back, this is a bit more work and less efficient, but we won't get into the problems from the method above.
With this implementation, we can store the actual correct path as part of the opened node, and the userspace can ask for it, i.e. if the user space want to know the canonicalize form of a path
It would be good to have "canonicalize" operation, where we can know the actual absolute path to a file without any '.' and '..'
There are two methods,
String manipulation
for example, converting
/welcome/../file
, we will get/file
.But this is not preferred, as something like this
/folder/file/../file2
will become/folder/file2
, which doesn't make sense, asfile
is a file, and doesn't have..
inside it.Treversing
The other method is to build the path while treversing, we will keep a
PathBuf
, and append to it when we go to a new folder, and pop when we go back, this is a bit more work and less efficient, but we won't get into the problems from the method above.With this implementation, we can store the actual correct path as part of the opened node, and the userspace can ask for it, i.e. if the user space want to know the
canonicalize
form of a path