[DTrace-devel] [PATCH v3] Add support for cleanpath() subroutine
Eugene Loh
eugene.loh at oracle.com
Thu Jan 25 02:06:44 UTC 2024
On 1/24/24 16:04, Kris Van Hees wrote:
> On Thu, Dec 21, 2023 at 01:11:25PM -0500, eugene.loh at oracle.com wrote:
>> Replace all "//" with "/".
>> Replace all "/./" with "/".
>> Replace all "/foo/.." with "/".
>>
>> Notice that the results differ in some cases from what was
>> done in legacy DTrace:
> Some comments on this (after reviewing the documentation again):
>
>> input string current patch legacy DTrace
>>
>> "/." "/" "/."
>> "a/." "a" "a/."
>> "./a" "a" "./a"
> These three seem correct to me in how the current patch handles it.
>
>> "../.." "../.." "."
>> "a/.." "." "a"
>> "a/../.." ".." "a"
> A case could be made for all of them being "",
I do not see how "../.." and "" are equivalent.
> given that cleanpath() is
> supposed to remove redundant elements (. and ..)
".." by itself is not redundant, but the combination "/foo/.." can be
collapsed.
> and no context is known
> for relative paths. But I do agree that there is also a case to be made
> to not get rid of .. elements that would apply to the root of the relative
> path, becausae discarding them effectively causes information loss.
>
> Except for the case of "a/..". That one should be "" because the .. should
> be considered redundant in view of having a present path element, and thus
> it is possible to back up one path element, which would yield "". I do not
> see how the result of "." would be considered valid because that in itself
> is a redundant element (and thus should still be removed).
I guess I just don't know what standard or use case to consider. Anyhow,
the documentation I saw speaks of removing "/./" without talking
specifically about "." in isolation. There are a lot of cases when
someone would not consider "." and "" to be the same... e.g., "cd .",
"pushd .", etc. So "a/.." is the same as ".". Are they also the same
as ""? It depends on the situation, and it's unclear to me where
cleanpath() is used. The documentation I saw (Oracle Linux DTrace
Guide) didn't say anything was wrong with a bare ".".
>> "a/../b" "b" "/b"
> I agree.
>
>> In the first set, legacy DTrace has unnecessary trailing "." or "/."
>> or unnecessary leading "./". They would seem to be wrong.
>>
>> In the next cases, the legacy results are clearly wrong, not
>> handling ".." correctly.
>>
>> In the final case, a relative path is converted into an absolute
>> path, which is also clearly incorrect.
More information about the DTrace-devel
mailing list