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); } /**