Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package archiver | 5 package archiver |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 return | 62 return |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 if strings.HasSuffix(root, string(filepath.Separator)) { | 65 if strings.HasSuffix(root, string(filepath.Separator)) { |
| 66 root = root[:len(root)-1] | 66 root = root[:len(root)-1] |
| 67 } | 67 } |
| 68 rootLen := len(root) + 1 | 68 rootLen := len(root) + 1 |
| 69 err := filepath.Walk(root, func(p string, info os.FileInfo, err error) e rror { | 69 err := filepath.Walk(root, func(p string, info os.FileInfo, err error) e rror { |
| 70 total++ | 70 total++ |
| 71 if err != nil { | 71 if err != nil { |
| 72 » » » return fmt.Errorf("walk(%s): %s", p, err) | 72 » » » return fmt.Errorf("walk(%q): %v", p, err) |
|
mithro
2016/11/29 03:43:44
This will cause the binary to fail if it tries to
djd-OOO-Apr2017
2016/11/29 03:51:55
Do you have a suggestion on how to check that? Als
| |
| 73 } | 73 } |
| 74 if len(p) <= rootLen { | 74 if len(p) <= rootLen { |
| 75 // Root directory. | 75 // Root directory. |
| 76 return nil | 76 return nil |
| 77 } | 77 } |
| 78 relPath := p[rootLen:] | 78 relPath := p[rootLen:] |
| 79 for _, b := range blacklist { | 79 for _, b := range blacklist { |
| 80 matched, _ := filepath.Match(b, relPath) | 80 matched, _ := filepath.Match(b, relPath) |
| 81 if !matched { | 81 if !matched { |
| 82 // Also check at the base file name. | 82 // Also check at the base file name. |
| 83 matched, _ = filepath.Match(b, filepath.Base(rel Path)) | 83 matched, _ = filepath.Match(b, filepath.Base(rel Path)) |
| 84 } | 84 } |
| 85 if matched { | 85 if matched { |
| 86 // Must not return io.SkipDir for file, filepath .walk() handles this | 86 // Must not return io.SkipDir for file, filepath .walk() handles this |
| 87 // badly. | 87 // badly. |
| 88 if info.IsDir() { | 88 if info.IsDir() { |
| 89 return filepath.SkipDir | 89 return filepath.SkipDir |
| 90 } | 90 } |
| 91 return nil | 91 return nil |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 if info.IsDir() { | 94 if info.IsDir() { |
| 95 return nil | 95 return nil |
| 96 } | 96 } |
| 97 c <- &walkItem{fullPath: p, relPath: relPath, info: info} | 97 c <- &walkItem{fullPath: p, relPath: relPath, info: info} |
| 98 return nil | 98 return nil |
| 99 }) | 99 }) |
| 100 if err != nil { | 100 if err != nil { |
| 101 » » c <- &walkItem{err: err} | 101 » » // No point continuing if an error occurred during walk. |
| 102 » » log.Fatalf("Unable to walk %q: %v", root, err) | |
|
tandrii(chromium)
2016/11/30 14:35:08
1. a test for this would be nice anyway - panic ca
M-A Ruel
2016/11/30 15:39:14
I'm not enthusiastic about hard failing vs cleanly
| |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 // PushDirectory walks a directory at root and creates a .isolated file. | 106 // PushDirectory walks a directory at root and creates a .isolated file. |
| 106 // | 107 // |
| 107 // It walks the directories synchronously, then returns a *Item to signal when | 108 // It walks the directories synchronously, then returns a *Item to signal when |
| 108 // the background work is completed. The Item is signaled once all files are | 109 // the background work is completed. The Item is signaled once all files are |
| 109 // hashed. In particular, the *Item is signaled before server side cache | 110 // hashed. In particular, the *Item is signaled before server side cache |
| 110 // lookups and upload is completed. Use archiver.Close() to wait for | 111 // lookups and upload is completed. Use archiver.Close() to wait for |
| 111 // completion. | 112 // completion. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 if err != nil { | 195 if err != nil { |
| 195 s.SetErr(err) | 196 s.SetErr(err) |
| 196 } | 197 } |
| 197 }() | 198 }() |
| 198 return s | 199 return s |
| 199 } | 200 } |
| OLD | NEW |