1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-06-30 21:28:28 +00:00

entry: rework e.Path() handling for casync-mtree

The core issue comes about when you consider a trivial example of a path
like "./README". This path is lexically equivalent within mtree to
"README", but a simple string comparison will yield the wrong result.
Instead you need to lexically clean the path first (filepath.Clean isn't
enough here -- you need to prepend a "/" and then do filepath.Clean).

In gomtree we generate spec files in the same style of FreeBSD's
mtree(8), so you would be very hard-pressed to find an example of such
an inconsistency. However casync's mtree implementation does not
generate leading "./" for root paths which results in "missing" entries.

The implementation of CleanPath was written by me for umoci originally,
then later I copied it to runc for other uses, and now I've copied it
here. Since I'm the sole author I'm effectively dual-licensing it under
this project's license to avoid having to relicense go-mtree for no good
reason (or deal with the multiple-license hassle).

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2018-09-14 08:44:46 +10:00
parent 37d776ac40
commit 4766cebac0
No known key found for this signature in database
GPG key ID: 9E18AA267DDB8DB4
2 changed files with 37 additions and 4 deletions

View file

@ -350,7 +350,6 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er
if err != nil {
return nil, err
}
//fmt.Printf("new: %q\n", path)
// Cannot take &kv because it's the iterator.
cEntry := new(Entry)
@ -373,7 +372,6 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er
if err != nil {
return nil, err
}
//fmt.Printf("old: %q\n", path)
// Cannot take &kv because it's the iterator.
cEntry := new(Entry)