|
@@ -1059,7 +1059,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
// 指定要删除的时间点(此处为当前时间之前的时间)
|
|
|
ZonedDateTime deleteTime = ZonedDateTime.now().minusDays(number); // 删除30天前的文件
|
|
|
|
|
|
- // 递归删除指定目录下的所有文件和空目录
|
|
|
+ // 删除指定目录下的所有文件和文件夹
|
|
|
deleteObjectsAndEmptyDirectoriesRecursively(minioClient, bucketName, prefix, deleteTime);
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("Error occurred: " + e);
|
|
@@ -1067,7 +1067,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
}
|
|
|
|
|
|
private static void deleteObjectsAndEmptyDirectoriesRecursively(MinioClient minioClient, String bucketName, String prefix, ZonedDateTime deleteTime) throws Exception {
|
|
|
- log.info("deleteObjectsAndEmptyDirectoriesRecursively");
|
|
|
Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder()
|
|
|
.bucket(bucketName)
|
|
|
.prefix(prefix)
|
|
@@ -1077,43 +1076,19 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
for (Result<Item> result : results) {
|
|
|
Item item = result.get();
|
|
|
ZonedDateTime itemLastModified = item.lastModified();
|
|
|
-
|
|
|
- // 检查文件夹的上次修改时间是否在删除时间之前
|
|
|
- log.info("删除时间:---"+deleteTime);
|
|
|
- log.info("上次修改时间:---"+itemLastModified);
|
|
|
- if (item.isDir() && itemLastModified.isBefore(deleteTime)) {
|
|
|
- // 获取下一级目录的时间
|
|
|
- ZonedDateTime nextLevelLastModified = getNextLevelDirectoryLastModified(minioClient, bucketName, item.objectName());
|
|
|
-
|
|
|
- // 如果下一级目录的时间早于删除时间,则删除当前目录
|
|
|
- log.info("下一级目录的时间:---"+nextLevelLastModified);
|
|
|
- if (nextLevelLastModified != null && nextLevelLastModified.isBefore(deleteTime)) {
|
|
|
- minioClient.removeObject(RemoveObjectArgs.builder()
|
|
|
- .bucket(bucketName)
|
|
|
- .object(item.objectName())
|
|
|
- .build());
|
|
|
- log.info("删除文件夹: " + item.objectName());
|
|
|
- }
|
|
|
+ log.info("删除的时间:"+deleteTime);
|
|
|
+ log.info("文件夹的时间:"+itemLastModified);
|
|
|
+ if (itemLastModified.isBefore(deleteTime)) {
|
|
|
+ // 删除文件或文件夹
|
|
|
+ minioClient.removeObject(RemoveObjectArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .object(item.objectName())
|
|
|
+ .build());
|
|
|
+ log.info("删除文件或文件夹: " + item.objectName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private static ZonedDateTime getNextLevelDirectoryLastModified(MinioClient minioClient, String bucketName, String prefix) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException {
|
|
|
- Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder()
|
|
|
- .bucket(bucketName)
|
|
|
- .prefix(prefix)
|
|
|
- .recursive(false) // 只获取当前目录下的内容
|
|
|
- .build());
|
|
|
-
|
|
|
- for (Result<Item> result : results) {
|
|
|
- Item item = result.get();
|
|
|
- if (item.isDir()) {
|
|
|
- return item.lastModified();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
public void test(Integer number) {
|