From e920ab0ec0511502d4a77fc7281aac0b9646c61f Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Mon, 8 Feb 2021 17:46:04 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=9B=A0=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=8A=9F=E8=83=BD=E5=AF=BC=E8=87=B4=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B1=E6=95=88=E7=9A=84=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhaojun/zfile/aspect/FileListCacheAspect.java | 3 ++- .../zfile/controller/home/FileController.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java b/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java index 22ee95e..f17c2ae 100644 --- a/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java +++ b/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java @@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.Collections; import java.util.List; /** @@ -50,7 +51,7 @@ public class FileListCacheAspect { if (enableCache) { List cacheFileList = zFileCache.get(driveId, path); if (cacheFileList == null) { - result = (List) point.proceed(); + result = Collections.unmodifiableList((List) point.proceed()); zFileCache.put(driveId, path, result); } else { result = cacheFileList; diff --git a/src/main/java/im/zhaojun/zfile/controller/home/FileController.java b/src/main/java/im/zhaojun/zfile/controller/home/FileController.java index ecd78a2..2233c12 100644 --- a/src/main/java/im/zhaojun/zfile/controller/home/FileController.java +++ b/src/main/java/im/zhaojun/zfile/controller/home/FileController.java @@ -1,5 +1,6 @@ package im.zhaojun.zfile.controller.home; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import im.zhaojun.zfile.context.DriveContext; import im.zhaojun.zfile.exception.NotExistFileException; @@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.HttpClientErrorException; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -85,18 +87,21 @@ public class FileController { AbstractBaseFileService fileService = driveContext.get(driveId); List fileItemList = fileService.fileList(StringUtils.removeDuplicateSeparator(ZFileConstant.PATH_SEPARATOR + path + ZFileConstant.PATH_SEPARATOR)); + // 创建副本, 防止排序和过滤对原数据产生影响 + List copyList = new ArrayList<>(fileItemList); + // 校验密码, 如果校验不通过, 则返回错误消息 - VerifyResult verifyResult = verifyPassword(fileItemList, driveId, path, password); + VerifyResult verifyResult = verifyPassword(copyList, driveId, path, password); if (!verifyResult.isPassed()) { return ResultBean.error(verifyResult.getMsg(), verifyResult.getCode()); } // 过滤掉驱动器配置的表达式中要隐藏的数据 - filterFileList(fileItemList, driveId); + filterFileList(copyList, driveId); // 按照自然排序 - fileItemList.sort(new FileComparator(orderBy, orderDirection)); - return ResultBean.successData(fileItemList); + copyList.sort(new FileComparator(orderBy, orderDirection)); + return ResultBean.successData(copyList); } /**