Commit 5ce4156
authored
Optimizations around directory traversing for sync exclusion (#3702)
## Changes
<!-- Brief summary of your changes that is easy to understand -->
1. Do not error out on a file that is removed / renamed while the path
is being traversed
2. Do not traverse path if exclusion directive is empty
## Why
<!-- Why are these changes needed? Provide the context that the reviewer
might be missing.
For example, were there any decisions behind the change that are not
reflected in the code itself? -->
1. I stumbled upon this error when working on local cache implementation
testing the case when a local cache dir is inside a `.databricks` folder
within a bundle. `recursiveListFiles` has a classic [TOCTOU
(Time-of-Check-Time-of-Use)](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use)
race condition - `WalkDir` collects directory entries first, but
`d.Info()` makes a fresh stat() syscall. If the file was
renamed/moved/deleted in between, the stat call fails because it's
looking for a path that no longer exists. This change proposes to **skip
the inner `stat` call**, so that the method will not throw an error on
an non-existing file
2. While looking into the `sync` behavior I noticed that it traverses
the bundle directory looking for files to include/exclude, even in case
when no files are configured to be included/excluded - the tree
traversal in this case is not necessary.
## Tests
<!-- How have you tested the changes? -->
Existing tests must pass
<!-- If your PR needs to be included in the release notes for next
release,
add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->1 parent 5e1d01e commit 5ce4156
2 files changed
+9
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | 99 | | |
101 | | - | |
| 100 | + | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
| |||
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
0 commit comments