- containerd/continuity#140 Fix directory comparison in changes
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -121,7 +121,7 @@ google.golang.org/genproto 694d95ba50e67b2e363f3483057d |
| 121 | 121 |
# containerd |
| 122 | 122 |
github.com/containerd/containerd ceba56893a76f22cf0126c46d835c80fb3833408 |
| 123 | 123 |
github.com/containerd/fifo a9fb20d87448d386e6d50b1f2e1fa70dcf0de43c |
| 124 |
-github.com/containerd/continuity 004b46473808b3e7a4a3049c20e4376c91eb966d |
|
| 124 |
+github.com/containerd/continuity aaeac12a7ffcd198ae25440a9dff125c2e2703a7 |
|
| 125 | 125 |
github.com/containerd/cgroups 4994991857f9b0ae8dc439551e8bebdbb4bf66c1 |
| 126 | 126 |
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23 |
| 127 | 127 |
github.com/containerd/go-runc 7d11b49dc0769f6dbb0d1b19f3d48524d1bad9ad |
| ... | ... |
@@ -22,7 +22,6 @@ import ( |
| 22 | 22 |
"io" |
| 23 | 23 |
"os" |
| 24 | 24 |
"path/filepath" |
| 25 |
- "strings" |
|
| 26 | 25 |
|
| 27 | 26 |
"github.com/pkg/errors" |
| 28 | 27 |
) |
| ... | ... |
@@ -47,9 +46,8 @@ func pathChange(lower, upper *currentPath) (ChangeKind, string) {
|
| 47 | 47 |
if upper == nil {
|
| 48 | 48 |
return ChangeKindDelete, lower.path |
| 49 | 49 |
} |
| 50 |
- // TODO: compare by directory |
|
| 51 | 50 |
|
| 52 |
- switch i := strings.Compare(lower.path, upper.path); {
|
|
| 51 |
+ switch i := directoryCompare(lower.path, upper.path); {
|
|
| 53 | 52 |
case i < 0: |
| 54 | 53 |
// File in lower that is not in upper |
| 55 | 54 |
return ChangeKindDelete, lower.path |
| ... | ... |
@@ -61,6 +59,35 @@ func pathChange(lower, upper *currentPath) (ChangeKind, string) {
|
| 61 | 61 |
} |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 |
+func directoryCompare(a, b string) int {
|
|
| 65 |
+ l := len(a) |
|
| 66 |
+ if len(b) < l {
|
|
| 67 |
+ l = len(b) |
|
| 68 |
+ } |
|
| 69 |
+ for i := 0; i < l; i++ {
|
|
| 70 |
+ c1, c2 := a[i], b[i] |
|
| 71 |
+ if c1 == filepath.Separator {
|
|
| 72 |
+ c1 = byte(0) |
|
| 73 |
+ } |
|
| 74 |
+ if c2 == filepath.Separator {
|
|
| 75 |
+ c2 = byte(0) |
|
| 76 |
+ } |
|
| 77 |
+ if c1 < c2 {
|
|
| 78 |
+ return -1 |
|
| 79 |
+ } |
|
| 80 |
+ if c1 > c2 {
|
|
| 81 |
+ return +1 |
|
| 82 |
+ } |
|
| 83 |
+ } |
|
| 84 |
+ if len(a) < len(b) {
|
|
| 85 |
+ return -1 |
|
| 86 |
+ } |
|
| 87 |
+ if len(a) > len(b) {
|
|
| 88 |
+ return +1 |
|
| 89 |
+ } |
|
| 90 |
+ return 0 |
|
| 91 |
+} |
|
| 92 |
+ |
|
| 64 | 93 |
func sameFile(f1, f2 *currentPath) (bool, error) {
|
| 65 | 94 |
if os.SameFile(f1.f, f2.f) {
|
| 66 | 95 |
return true, nil |