|
32 | 32 | import java.nio.file.FileSystems; |
33 | 33 | import java.nio.file.Files; |
34 | 34 | import java.nio.file.Path; |
| 35 | +import java.nio.file.attribute.FileTime; |
| 36 | +import java.time.Instant; |
35 | 37 | import java.util.LinkedHashMap; |
36 | 38 | import java.util.List; |
37 | 39 | import java.util.Map; |
@@ -135,26 +137,27 @@ public void copyDirectory(Path src, Path dest) throws IOException { |
135 | 137 | } |
136 | 138 |
|
137 | 139 | /** |
138 | | - * Assumes the destination directory exists. |
| 140 | + * Create a deterministic order of paths for creation time. |
| 141 | + * This is so last modified time indexing is stable in tests. Note we cannot use |
| 142 | + * Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES) as the original creation time is the user |
| 143 | + * checkout and not different across files. |
| 144 | + * |
139 | 145 | * @param src source directory |
140 | 146 | * @param dest destination directory |
141 | 147 | * @throws IOException on error |
142 | 148 | */ |
143 | 149 | public void copyDirectoryWithUniqueModifiedTime(Path src, Path dest) throws IOException { |
144 | | - // Create a deterministic order of paths for creation time, so last modified time indexing is stable in tests |
145 | | - // note we cannot use Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES) |
146 | | - // as the original creation time is the user checkout and not different accross files |
147 | | - List<Path> allPaths; |
| 150 | + List<Path> allPaths; |
148 | 151 | try (Stream<Path> stream = Files.walk(src)) { |
149 | 152 | allPaths = stream.filter(p -> !p.equals(src)).sorted().toList(); |
150 | 153 | } |
151 | 154 | // Set base time to now, and go ahead in time for each subsequent path by 1 minute |
152 | | - java.time.Instant baseTime = java.time.Instant.now(); |
| 155 | + Instant baseTime = java.time.Instant.now(); |
153 | 156 | for (int i = 0; i < allPaths.size(); i++) { |
154 | 157 | Path sourcePath = allPaths.get(i); |
155 | 158 | Path destRelativePath = getDestinationRelativePath(src, sourcePath); |
156 | 159 | Path destPath = dest.resolve(destRelativePath); |
157 | | - var fileTime = java.nio.file.attribute.FileTime.from(baseTime.plusSeconds(i * 60L)); |
| 160 | + var fileTime = FileTime.from(baseTime.plusSeconds(i * 60L)); |
158 | 161 | if (Files.isDirectory(sourcePath)) { |
159 | 162 | if (!Files.exists(destPath)) { |
160 | 163 | Files.createDirectories(destPath); |
|
0 commit comments