LibraryDownloader: Don't leak DirectoryStream
Change-Id: I6941ac6470c75f3d99247f909cb1328a837524a7
This commit is contained in:

committed by
David Pursehouse

parent
62e67bede7
commit
c9cc436cd6
@@ -216,29 +216,28 @@ class LibraryDownloader {
|
|||||||
|
|
||||||
private void removeStaleVersions() {
|
private void removeStaleVersions() {
|
||||||
if (!Strings.isNullOrEmpty(remove)) {
|
if (!Strings.isNullOrEmpty(remove)) {
|
||||||
Iterable<Path> paths;
|
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
|
||||||
try {
|
@Override
|
||||||
paths = Files.newDirectoryStream(lib_dir,
|
public boolean accept(Path entry) {
|
||||||
new DirectoryStream.Filter<Path>() {
|
return entry.getFileName().toString()
|
||||||
@Override
|
.matches("^" + remove + "$");
|
||||||
public boolean accept(Path entry) {
|
}
|
||||||
return entry.getFileName().toString()
|
};
|
||||||
.matches("^" + remove + "$");
|
try (DirectoryStream<Path> paths =
|
||||||
}
|
Files.newDirectoryStream(lib_dir, filter)) {
|
||||||
});
|
for (Path p : paths) {
|
||||||
|
String old = p.getFileName().toString();
|
||||||
|
String bak = "." + old + ".backup";
|
||||||
|
ui.message("Renaming %s to %s", old, bak);
|
||||||
|
try {
|
||||||
|
Files.move(p, p.resolveSibling(bak));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Die("cannot rename " + old, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Die("cannot remove stale library versions", e);
|
throw new Die("cannot remove stale library versions", e);
|
||||||
}
|
}
|
||||||
for (Path p : paths) {
|
|
||||||
String old = p.getFileName().toString();
|
|
||||||
String bak = "." + old + ".backup";
|
|
||||||
ui.message("Renaming %s to %s", old, bak);
|
|
||||||
try {
|
|
||||||
Files.move(p, p.resolveSibling(bak));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new Die("cannot rename " + old, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user