mirror of
https://github.com/cryptomator/cryptomator.git
synced 2024-11-27 14:00:38 +00:00
fix resource leak
This commit is contained in:
parent
085304ec04
commit
f277d4d21b
@ -66,9 +66,9 @@ class MountPointHelper {
|
||||
private void clearIrregularUnmountDebris(Path dirContainingMountPoints) {
|
||||
IOException cleanupFailed = new IOException("Cleanup failed");
|
||||
|
||||
try {
|
||||
try (var ds = Files.newDirectoryStream(dirContainingMountPoints)) {
|
||||
LOG.debug("Performing cleanup of mountpoint dir {}.", dirContainingMountPoints);
|
||||
for (Path p : Files.newDirectoryStream(dirContainingMountPoints)) {
|
||||
for (Path p : ds) {
|
||||
try {
|
||||
var attr = Files.readAttributes(p, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
|
||||
if (attr.isOther() && attr.isDirectory()) { // yes, this is possible with windows junction points -.-
|
||||
@ -113,8 +113,10 @@ class MountPointHelper {
|
||||
}
|
||||
|
||||
private void ensureIsEmpty(Path dir) throws IOException {
|
||||
if (Files.newDirectoryStream(dir).iterator().hasNext()) {
|
||||
throw new DirectoryNotEmptyException(dir.toString());
|
||||
try (var ds = Files.newDirectoryStream(dir)) {
|
||||
if (ds.iterator().hasNext()){
|
||||
throw new DirectoryNotEmptyException(dir.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,11 @@ import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.StandardProtocolFamily;
|
||||
import java.net.UnixDomainSocketAddress;
|
||||
import java.nio.channels.AlreadyBoundException;
|
||||
import java.nio.channels.AsynchronousCloseException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.UnsupportedAddressTypeException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.Executor;
|
||||
@ -29,10 +31,18 @@ class Server implements IpcCommunicator {
|
||||
public static Server create(Path socketPath) throws IOException {
|
||||
Files.createDirectories(socketPath.getParent());
|
||||
var address = UnixDomainSocketAddress.of(socketPath);
|
||||
var serverSocketChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
||||
serverSocketChannel.bind(address);
|
||||
LOG.info("Spawning IPC server listening on socket {}", socketPath);
|
||||
return new Server(serverSocketChannel, socketPath);
|
||||
ServerSocketChannel ch = null;
|
||||
try {
|
||||
ch = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
||||
ch.bind(address);
|
||||
LOG.info("Spawning IPC server listening on socket {}", socketPath);
|
||||
return new Server(ch, socketPath);
|
||||
} catch (IOException | AlreadyBoundException | UnsupportedAddressTypeException e) {
|
||||
if (ch != null) {
|
||||
ch.close();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user