From eb15b75818190bafb83bca40e1cdbec596c40997 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 28 Apr 2020 14:37:48 +0200 Subject: [PATCH 1/4] add exception handling when underlying file system does not support long file names --- .../frontend/dokany/ReadWriteAdapter.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java index 21ef890..a53ecc2 100644 --- a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java +++ b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java @@ -15,6 +15,7 @@ import com.dokany.java.structure.FullFileInfo; import com.dokany.java.structure.VolumeInformation; import com.google.common.base.CharMatcher; +import com.google.common.base.Strings; import com.sun.jna.Pointer; import com.sun.jna.WString; import com.sun.jna.platform.win32.WinBase; @@ -35,6 +36,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 +152,15 @@ private int createDirectory(Path path, CreationDisposition creationDisposition, LOG.trace("Directory {} already exists.", path); return Win32ErrorCode.ERROR_ALREADY_EXISTS.getMask(); } + } catch (FileSystemException e) { + if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { + LOG.warn("zwCreateFile(): Creation of {} failed, name too long.", path); + return Win32ErrorCode.ERROR_BUFFER_OVERFLOW.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); @@ -240,6 +251,15 @@ 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) { + if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { + LOG.warn("zwCreateFile(): Creation of {} failed, name too long.", path); + return Win32ErrorCode.ERROR_BUFFER_OVERFLOW.getMask(); + } else { + LOG.debug("zwCreateFile(): IO error occured while opening handle to {}.", 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 +792,22 @@ 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) { + if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { + LOG.warn("({}) Moving resource {} failed, name too long.", path); + return Win32ErrorCode.ERROR_BUFFER_OVERFLOW.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(); } From 05f5c919a17657d87f030b5acab7b519cb54a4d3 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 28 Apr 2020 15:51:48 +0200 Subject: [PATCH 2/4] Used wrong error code, fixed that. --- .../frontend/dokany/ReadWriteAdapter.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java index a53ecc2..ff099ac 100644 --- a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java +++ b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java @@ -154,8 +154,8 @@ private int createDirectory(Path path, CreationDisposition creationDisposition, } } catch (FileSystemException e) { if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { - LOG.warn("zwCreateFile(): Creation of {} failed, name too long.", path); - return Win32ErrorCode.ERROR_BUFFER_OVERFLOW.getMask(); + 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); @@ -253,8 +253,8 @@ else if ((attr != null && attr.isReadOnly() || ((rawFileAttributes & FileAttribu return Win32ErrorCode.ERROR_ACCESS_DENIED.getMask(); } catch (FileSystemException e) { if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { - LOG.warn("zwCreateFile(): Creation of {} failed, name too long.", path); - return Win32ErrorCode.ERROR_BUFFER_OVERFLOW.getMask(); + 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 while opening handle to {}.", path); LOG.debug("zwCreateFile(): ", e); @@ -799,8 +799,8 @@ public int moveFile(WString rawPath, WString rawNewFileName, boolean rawReplaceI return Win32ErrorCode.ERROR_DIR_NOT_EMPTY.getMask(); } catch (FileSystemException e) { if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { - LOG.warn("({}) Moving resource {} failed, name too long.", path); - return Win32ErrorCode.ERROR_BUFFER_OVERFLOW.getMask(); + 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); From 655eb91e77203722c2b27876a8c9f6dabf7dd9e4 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 28 Apr 2020 18:03:27 +0200 Subject: [PATCH 3/4] closes #38 --- .../frontend/dokany/ReadWriteAdapter.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java index ff099ac..86ec2a4 100644 --- a/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java +++ b/src/main/java/org/cryptomator/frontend/dokany/ReadWriteAdapter.java @@ -15,7 +15,6 @@ import com.dokany.java.structure.FullFileInfo; import com.dokany.java.structure.VolumeInformation; import com.google.common.base.CharMatcher; -import com.google.common.base.Strings; import com.sun.jna.Pointer; import com.sun.jna.WString; import com.sun.jna.platform.win32.WinBase; @@ -153,7 +152,8 @@ private int createDirectory(Path path, CreationDisposition creationDisposition, return Win32ErrorCode.ERROR_ALREADY_EXISTS.getMask(); } } catch (FileSystemException e) { - if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { + 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 { @@ -193,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(); @@ -252,11 +253,12 @@ else if ((attr != null && attr.isReadOnly() || ((rawFileAttributes & FileAttribu LOG.trace("Cause:", e); return Win32ErrorCode.ERROR_ACCESS_DENIED.getMask(); } catch (FileSystemException e) { - if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { + 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 while opening handle to {}.", path); + LOG.debug("zwCreateFile(): IO error occured during the creation of {}.", path); LOG.debug("zwCreateFile(): ", e); return Win32ErrorCode.ERROR_CANNOT_MAKE.getMask(); } @@ -798,7 +800,8 @@ public int moveFile(WString rawPath, WString rawNewFileName, boolean rawReplaceI LOG.trace("({}) Target directory {} is not emtpy.", dokanyFileInfo.Context, path); return Win32ErrorCode.ERROR_DIR_NOT_EMPTY.getMask(); } catch (FileSystemException e) { - if (Strings.nullToEmpty(e.getReason()).contains("path too long")) { + 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 { @@ -964,5 +967,4 @@ private Path getRootedPath(WString rawPath) { assert root.isAbsolute(); return root.resolve(relativeUnixPath); } - } From bb0e4d08804d6b6ba7d660226c9265430c688054 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 28 Apr 2020 18:06:29 +0200 Subject: [PATCH 4/4] preparing 1.1.14 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9fb7f22..f69f0e8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.cryptomator dokany-nio-adapter - 1.2.0-SNAPSHOT + 1.1.14 Access resources at a given NIO path via Dokany. Dokany-NIO Adapter https://github.com/cryptomator/dokany-nio-adapter