From 75f3275e15bc2e195e2cd4901de7d171c3675b62 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Sat, 21 Sep 2024 12:01:48 +0800
Subject: [PATCH] 修复角色禁用权限不失效问题

---
 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java |   74 +++++++++++++++++++++++++++++++------
 1 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java
index 24e850c..0c28db7 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java
@@ -18,8 +18,14 @@
  * 
  * @author ruoyi
  */
-public class FileUtils extends org.apache.commons.io.FileUtils
+public class FileUtils
 {
+    /** 字符常量:斜杠 {@code '/'} */
+    public static final char SLASH = '/';
+
+    /** 字符常量:反斜杠 {@code '\\'} */
+    public static final char BACKSLASH = '\\';
+
     public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
 
     /**
@@ -91,8 +97,7 @@
         // 路径为文件且不为空则进行删除
         if (file.isFile() && file.exists())
         {
-            file.delete();
-            flag = true;
+            flag = file.delete();
         }
         return flag;
     }
@@ -121,15 +126,8 @@
         {
             return false;
         }
-
-        // 检查允许下载的文件规则
-        if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource)))
-        {
-            return true;
-        }
-
-        // 不在允许下载的文件规则
-        return false;
+        // 判断是否在允许下载的文件规则内
+        return ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource));
     }
 
     /**
@@ -168,6 +166,57 @@
     }
 
     /**
+     * 返回文件名
+     *
+     * @param filePath 文件
+     * @return 文件名
+     */
+    public static String getName(String filePath)
+    {
+        if (null == filePath)
+        {
+            return null;
+        }
+        int len = filePath.length();
+        if (0 == len)
+        {
+            return filePath;
+        }
+        if (isFileSeparator(filePath.charAt(len - 1)))
+        {
+            // 以分隔符结尾的去掉结尾分隔符
+            len--;
+        }
+
+        int begin = 0;
+        char c;
+        for (int i = len - 1; i > -1; i--)
+        {
+            c = filePath.charAt(i);
+            if (isFileSeparator(c))
+            {
+                // 查找最后一个路径分隔符(/或者\)
+                begin = i + 1;
+                break;
+            }
+        }
+
+        return filePath.substring(begin, len);
+    }
+
+    /**
+     * 是否为Windows或者Linux(Unix)文件分隔符<br>
+     * Windows平台下分隔符为\,Linux(Unix)为/
+     *
+     * @param c 字符
+     * @return 是否为Windows或者Linux(Unix)文件分隔符
+     */
+    public static boolean isFileSeparator(char c)
+    {
+        return SLASH == c || BACKSLASH == c;
+    }
+
+    /**
      * 下载文件名重新编码
      *
      * @param response 响应对象
@@ -187,6 +236,7 @@
                 .append(percentEncodedFileName);
 
         response.setHeader("Content-disposition", contentDispositionValue.toString());
+        response.setHeader("download-filename", percentEncodedFileName);
     }
 
     /**

--
Gitblit v1.9.3