diff --git a/pom.xml b/pom.xml index d38dd20..f69f0e8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.cryptomator dokany-nio-adapter - 1.1.13 + 1.1.14 Access resources at a given NIO path via Dokany. Dokany-NIO Adapter https://github.com/cryptomator/dokany-nio-adapter diff --git a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java index 21ef890..86ec2a4 100644 --- a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java +++ b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java @@ -35,6 +35,7 @@ import java.nio.file.DirectoryStream; import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileStore; +import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.LinkOption; @@ -150,6 +151,16 @@ private int createDirectory(Path path, CreationDisposition creationDisposition, LOG.trace("Directory {} already exists.", path); return Win32ErrorCode.ERROR_ALREADY_EXISTS.getMask(); } + } catch (FileSystemException e) { + final String reason = e.getReason().toLowerCase(); + if (reason.contains("path too long") || reason.contains("extension too long") || reason.contains("path too long")) { + LOG.warn("zwCreateFile(): Creation of {} failed, file name too long.", path); + return Win32ErrorCode.ERROR_FILENAME_EXCED_RANGE.getMask(); + } else { + LOG.debug("zwCreateFile(): IO error occured during the creation of {}.", path); + LOG.debug("zwCreateFile(): ", e); + return Win32ErrorCode.ERROR_CANNOT_MAKE.getMask(); + } } catch (IOException e) { //we dont know what the hell happened LOG.debug("zwCreateFile(): IO error occured during the creation of {}.", path); @@ -182,6 +193,7 @@ private int createDirectory(Path path, CreationDisposition creationDisposition, } } + private int createFile(Path path, CreationDisposition creationDisposition, Set openOptions, int rawFileAttributes, DokanyFileInfo dokanyFileInfo) { LOG.trace("Try to open {} as File.", path); final int mask = creationDisposition.getMask(); @@ -240,6 +252,16 @@ else if ((attr != null && attr.isReadOnly() || ((rawFileAttributes & FileAttribu LOG.trace("zwCreateFile(): Access to file {} was denied.", path); LOG.trace("Cause:", e); return Win32ErrorCode.ERROR_ACCESS_DENIED.getMask(); + } catch (FileSystemException e) { + final String reason = e.getReason().toLowerCase(); + if (reason.contains("path too long") || reason.contains("extension too long") || reason.contains("path too long")) { + LOG.warn("zwCreateFile(): Creation of {} failed, file name too long.", path); + return Win32ErrorCode.ERROR_FILENAME_EXCED_RANGE.getMask(); + } else { + LOG.debug("zwCreateFile(): IO error occured during the creation of {}.", path); + LOG.debug("zwCreateFile(): ", e); + return Win32ErrorCode.ERROR_CANNOT_MAKE.getMask(); + } } catch (IOException e) { if (attr != null) { LOG.debug("zwCreateFile(): IO error occurred during opening handle to {}.", path); @@ -772,13 +794,23 @@ public int moveFile(WString rawPath, WString rawNewFileName, boolean rawReplaceI LOG.trace("({}) Successful moved resource {} to {}.", dokanyFileInfo.Context, path, newPath); return Win32ErrorCode.ERROR_SUCCESS.getMask(); } catch (FileAlreadyExistsException e) { - LOG.trace("({}) Ressource {} already exists at {}.", dokanyFileInfo.Context, path, newPath); + LOG.trace("({}) Resource {} already exists at {}.", dokanyFileInfo.Context, path, newPath); return Win32ErrorCode.ERROR_FILE_EXISTS.getMask(); } catch (DirectoryNotEmptyException e) { - LOG.trace("({}) Target directoy {} is not emtpy.", dokanyFileInfo.Context, path); + LOG.trace("({}) Target directory {} is not emtpy.", dokanyFileInfo.Context, path); return Win32ErrorCode.ERROR_DIR_NOT_EMPTY.getMask(); + } catch (FileSystemException e) { + final String reason = e.getReason().toLowerCase(); + if (reason.contains("path too long") || reason.contains("extension too long") || reason.contains("path too long")) { + LOG.warn("({}) Moving resource {} failed, file name too long.", dokanyFileInfo.Context, path); + return Win32ErrorCode.ERROR_FILENAME_EXCED_RANGE.getMask(); + } else { + LOG.debug("({}) moveFile(): IO error while moving resource {}.", dokanyFileInfo.Context, path); + LOG.debug("moveFile(): ", e); + return Win32ErrorCode.ERROR_GEN_FAILURE.getMask(); + } } catch (IOException e) { - LOG.debug("({}) moveFile(): IO error occured while moving ressource {}.", dokanyFileInfo.Context, path); + LOG.debug("({}) moveFile(): IO error while moving resource {}.", dokanyFileInfo.Context, path); LOG.debug("moveFile(): ", e); return Win32ErrorCode.ERROR_GEN_FAILURE.getMask(); } @@ -935,5 +967,4 @@ private Path getRootedPath(WString rawPath) { assert root.isAbsolute(); return root.resolve(relativeUnixPath); } - }