|
13 | 13 | // limitations under the License.
|
14 | 14 | package com.google.devtools.build.lib.worker;
|
15 | 15 |
|
| 16 | +import static com.google.devtools.build.lib.vfs.Dirent.Type.DIRECTORY; |
| 17 | +import static com.google.devtools.build.lib.vfs.Dirent.Type.SYMLINK; |
| 18 | + |
16 | 19 | import com.google.common.collect.Iterables;
|
17 | 20 | import com.google.devtools.build.lib.cmdline.LabelConstants;
|
18 | 21 | import com.google.devtools.build.lib.sandbox.SandboxHelpers;
|
19 | 22 | import com.google.devtools.build.lib.sandbox.SandboxHelpers.SandboxInputs;
|
20 | 23 | import com.google.devtools.build.lib.sandbox.SandboxHelpers.SandboxOutputs;
|
21 |
| -import com.google.devtools.build.lib.vfs.FileStatus; |
| 24 | +import com.google.devtools.build.lib.vfs.Dirent; |
22 | 25 | import com.google.devtools.build.lib.vfs.FileSystemUtils;
|
23 | 26 | import com.google.devtools.build.lib.vfs.Path;
|
24 | 27 | import com.google.devtools.build.lib.vfs.PathFragment;
|
@@ -109,36 +112,38 @@ private void cleanExisting(
|
109 | 112 | Set<PathFragment> dirsToCreate)
|
110 | 113 | throws IOException {
|
111 | 114 | Path execroot = workDir.getParentDirectory();
|
112 |
| - for (Path path : root.getDirectoryEntries()) { |
113 |
| - FileStatus stat = path.stat(Symlinks.NOFOLLOW); |
| 115 | + for (Dirent dirent : root.readdir(Symlinks.NOFOLLOW)) { |
| 116 | + Path absPath = root.getChild(dirent.getName()); |
114 | 117 | PathFragment pathRelativeToWorkDir;
|
115 |
| - if (path.startsWith(workDir)) { |
| 118 | + if (absPath.startsWith(workDir)) { |
116 | 119 | // path is under workDir, i.e. execroot/<workspace name>. Simply get the relative path.
|
117 |
| - pathRelativeToWorkDir = path.relativeTo(workDir); |
| 120 | + pathRelativeToWorkDir = absPath.relativeTo(workDir); |
118 | 121 | } else {
|
119 | 122 | // path is not under workDir, which means it belongs to one of external repositories
|
120 | 123 | // symlinked directly under execroot. Get the relative path based on there and prepend it
|
121 | 124 | // with the designated prefix, '../', so that it's still a valid relative path to workDir.
|
122 | 125 | pathRelativeToWorkDir =
|
123 |
| - LabelConstants.EXPERIMENTAL_EXTERNAL_PATH_PREFIX.getRelative(path.relativeTo(execroot)); |
| 126 | + LabelConstants.EXPERIMENTAL_EXTERNAL_PATH_PREFIX.getRelative( |
| 127 | + absPath.relativeTo(execroot)); |
124 | 128 | }
|
125 | 129 | Optional<PathFragment> destination =
|
126 | 130 | getExpectedSymlinkDestination(pathRelativeToWorkDir, inputs);
|
127 | 131 | if (destination.isPresent()) {
|
128 |
| - if (stat.isSymbolicLink() && path.readSymbolicLink().equals(destination.get())) { |
| 132 | + if (SYMLINK.equals(dirent.getType()) |
| 133 | + && absPath.readSymbolicLink().equals(destination.get())) { |
129 | 134 | inputsToCreate.remove(pathRelativeToWorkDir);
|
130 | 135 | } else {
|
131 |
| - path.delete(); |
| 136 | + absPath.delete(); |
132 | 137 | }
|
133 |
| - } else if (stat.isDirectory()) { |
| 138 | + } else if (DIRECTORY.equals(dirent.getType())) { |
134 | 139 | if (dirsToCreate.contains(pathRelativeToWorkDir)) {
|
135 |
| - cleanExisting(path, inputs, inputsToCreate, dirsToCreate); |
| 140 | + cleanExisting(absPath, inputs, inputsToCreate, dirsToCreate); |
136 | 141 | dirsToCreate.remove(pathRelativeToWorkDir);
|
137 | 142 | } else {
|
138 |
| - path.deleteTree(); |
| 143 | + absPath.deleteTree(); |
139 | 144 | }
|
140 | 145 | } else if (!inputsToCreate.contains(pathRelativeToWorkDir)) {
|
141 |
| - path.delete(); |
| 146 | + absPath.delete(); |
142 | 147 | }
|
143 | 148 | }
|
144 | 149 | }
|
|
0 commit comments