From 9588d3d5db6dea9ae253b468f36a30c3286f2192 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Sun, 3 Apr 2022 20:46:31 +0200 Subject: [PATCH] Simplify conditions and avoid extra compute. --- .../java/org/apache/ftpserver/command/impl/MD5.java | 6 +----- .../org/apache/ftpserver/command/impl/OPTS_MLST.java | 12 +++--------- .../filesystem/nativefs/NativeFileSystemFactory.java | 3 +-- .../ftpserver/impl/IODataConnectionFactory.java | 6 +----- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/MD5.java b/core/src/main/java/org/apache/ftpserver/command/impl/MD5.java index 881951a8..3e21b55b 100644 --- a/core/src/main/java/org/apache/ftpserver/command/impl/MD5.java +++ b/core/src/main/java/org/apache/ftpserver/command/impl/MD5.java @@ -61,11 +61,7 @@ public void execute(final FtpIoSession session, // reset state variables session.resetState(); - boolean isMMD5 = false; - - if ("MMD5".equals(request.getCommand())) { - isMMD5 = true; - } + boolean isMMD5 = "MMD5".equals(request.getCommand()); // print file information String argument = request.getArgument(); diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java b/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java index 196d619a..cd62a091 100644 --- a/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java +++ b/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java @@ -76,15 +76,9 @@ public void execute(final FtpIoSession session, } // set the list types String[] validatedTypes = validateSelectedTypes(types); - if (validatedTypes != null) { - session.setAttribute("MLST.types", validatedTypes); - session.write(LocalizedFtpReply.translate(session, request, context, - FtpReply.REPLY_200_COMMAND_OKAY, "OPTS.MLST", listTypes)); - } else { - session.write(LocalizedFtpReply.translate(session, request, context, - FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, - "OPTS.MLST", listTypes)); - } + session.setAttribute("MLST.types", validatedTypes); + session.write(LocalizedFtpReply.translate(session, request, context, + FtpReply.REPLY_200_COMMAND_OKAY, "OPTS.MLST", listTypes)); } private String[] validateSelectedTypes(final String types[]) { diff --git a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java index f15a19de..71d301ba 100644 --- a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java +++ b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java @@ -98,9 +98,8 @@ public FileSystemView createFileSystemView(User user) throws FtpException { } } - FileSystemView fsView = new NativeFileSystemView(user, + return new NativeFileSystemView(user, caseInsensitive); - return fsView; } } diff --git a/core/src/main/java/org/apache/ftpserver/impl/IODataConnectionFactory.java b/core/src/main/java/org/apache/ftpserver/impl/IODataConnectionFactory.java index 180800ff..46134089 100644 --- a/core/src/main/java/org/apache/ftpserver/impl/IODataConnectionFactory.java +++ b/core/src/main/java/org/apache/ftpserver/impl/IODataConnectionFactory.java @@ -432,11 +432,7 @@ public synchronized boolean isTimeout(final long currTime) { } // idle time is within limit - not a timeout - if ((currTime - requestTime) < maxIdleTime) { - return false; - } - - return true; + return (currTime - requestTime) >= maxIdleTime; } /**