From 361f4ce65787913c008a984b9fec194ed390e5e5 Mon Sep 17 00:00:00 2001 From: Guilherme Chaguri Date: Thu, 21 Jun 2018 22:44:28 -0300 Subject: [PATCH] Added permission error handling --- .../guichaguri/minimalftp/impl/NativeFileSystem.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/guichaguri/minimalftp/impl/NativeFileSystem.java b/src/main/java/com/guichaguri/minimalftp/impl/NativeFileSystem.java index 2abc988..c27253c 100644 --- a/src/main/java/com/guichaguri/minimalftp/impl/NativeFileSystem.java +++ b/src/main/java/com/guichaguri/minimalftp/impl/NativeFileSystem.java @@ -200,9 +200,13 @@ public void rename(File from, File to) throws IOException { @Override public void chmod(File file, int perms) throws IOException { - file.setReadable(Utils.hasPermission(perms, Utils.CAT_OWNER + Utils.TYPE_READ), true); - file.setWritable(Utils.hasPermission(perms, Utils.CAT_OWNER + Utils.TYPE_WRITE), true); - file.setExecutable(Utils.hasPermission(perms, Utils.CAT_OWNER + Utils.TYPE_EXECUTE), true); + boolean read = Utils.hasPermission(perms, Utils.CAT_OWNER + Utils.TYPE_READ); + boolean write = Utils.hasPermission(perms, Utils.CAT_OWNER + Utils.TYPE_WRITE); + boolean execute = Utils.hasPermission(perms, Utils.CAT_OWNER + Utils.TYPE_EXECUTE); + + if(!file.setReadable(read, true)) throw new IOException("Couldn't update the readable permission"); + if(!file.setWritable(write, true)) throw new IOException("Couldn't update the writable permission"); + if(!file.setExecutable(execute, true)) throw new IOException("Couldn't update the executable permission"); } @Override