90 // where some of the files have already been committed. Ignore it and continue.
91 continue;
92 }
93 localStorage.push(hash, storage.url(), storageRef);
94 }
95 }
96 }
97
98 private static void clearDirectory(Path directory) {
99 try (var files = Files.walk(directory)) {
100 files.map(Path::toFile)
101 .sorted(Comparator.reverseOrder())
102 .forEach(File::delete);
103 } catch (IOException io) {
104 throw new RuntimeException(io);
105 }
106 }
107
108 URI createAndArchive(PullRequestInstance prInstance, Path scratchPath, Hash base, Hash head, String identifier) {
109 try {
110 var localStorage = Repository.materialize(scratchPath, storage.url(), storageRef);
111 var relativeFolder = baseFolder.resolve(String.format("%s/webrev.%s", prInstance.id(), identifier));
112 var outputFolder = scratchPath.resolve(relativeFolder);
113 // If a previous operation was interrupted there may be content here already - overwrite if so
114 if (Files.exists(outputFolder)) {
115 clearDirectory(outputFolder);
116 }
117 generate(prInstance, outputFolder, base, head);
118 if (!localStorage.isClean()) {
119 push(localStorage, outputFolder, baseFolder.resolve(prInstance.id()).toString());
120 }
121 return URIBuilder.base(baseUri).appendPath(relativeFolder.toString().replace('\\', '/')).build();
122 } catch (IOException e) {
123 throw new UncheckedIOException(e);
124 }
125 }
126 }
|
90 // where some of the files have already been committed. Ignore it and continue.
91 continue;
92 }
93 localStorage.push(hash, storage.url(), storageRef);
94 }
95 }
96 }
97
98 private static void clearDirectory(Path directory) {
99 try (var files = Files.walk(directory)) {
100 files.map(Path::toFile)
101 .sorted(Comparator.reverseOrder())
102 .forEach(File::delete);
103 } catch (IOException io) {
104 throw new RuntimeException(io);
105 }
106 }
107
108 URI createAndArchive(PullRequestInstance prInstance, Path scratchPath, Hash base, Hash head, String identifier) {
109 try {
110 var localStorage = Repository.materialize(scratchPath, storage.url(),
111 "+" + storageRef + ":mlbridge_webrevs");
112 var relativeFolder = baseFolder.resolve(String.format("%s/webrev.%s", prInstance.id(), identifier));
113 var outputFolder = scratchPath.resolve(relativeFolder);
114 // If a previous operation was interrupted there may be content here already - overwrite if so
115 if (Files.exists(outputFolder)) {
116 clearDirectory(outputFolder);
117 }
118 generate(prInstance, outputFolder, base, head);
119 if (!localStorage.isClean()) {
120 push(localStorage, outputFolder, baseFolder.resolve(prInstance.id()).toString());
121 }
122 return URIBuilder.base(baseUri).appendPath(relativeFolder.toString().replace('\\', '/')).build();
123 } catch (IOException e) {
124 throw new UncheckedIOException(e);
125 }
126 }
127 }
|