Przeglądaj źródła

update dfs-store

reghao 2 lat temu
rodzic
commit
532ede38ab

+ 5 - 0
dfs-store/bin/shutdown.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+app='dfs-store.jar'
+pid=`jps | grep ${app} | awk '{print $1}'`
+kill -15 ${pid}

+ 5 - 0
dfs-store/bin/start.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+app='dfs-store.jar'
+app_path=`pwd`/${app}
+nohup java -jar ${app_path} > console.log 2>&1 &

+ 3 - 3
dfs-store/src/main/java/cn/reghao/dfs/store/service/GetObjectService.java

@@ -79,10 +79,10 @@ public class GetObjectService {
                 writeContentRange(objectMeta, contentRange.getStart(), contentRange.getEnd());
             }
         } else {
-            if (userAgent.contains("aws-sdk-java") || host.contains("oss.reghao.cn")) {
-                writeDownloadContent(objectMeta);
-            } else {
+            if (host.contains("oss.reghao.cn")) {
                 writeWholeContent(objectMeta);
+            } else {
+                writeDownloadContent(objectMeta);
             }
         }
     }

+ 58 - 0
dfs-store/src/test/java/FileMetaTest.java

@@ -2,7 +2,9 @@ import cn.reghao.dfs.store.DfsStoreApplication;
 import cn.reghao.dfs.store.db.mapper.FileMetaMapper;
 import cn.reghao.dfs.store.model.po.FileMeta;
 import cn.reghao.jutil.jdk.db.Page;
+import cn.reghao.jutil.jdk.security.DigestUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -10,6 +12,14 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.FileVisitor;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
 /**
@@ -64,4 +74,52 @@ public class FileMetaTest {
             log.info("page -> {}", pageNumber);
         }
     }
+
+    public void walkDir(Path path) throws IOException {
+        Files.walkFileTree(path, new FileVisitor<>() {
+            @Override
+            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+                String absolutePath = file.toString();
+                process(absolutePath);
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+                return FileVisitResult.CONTINUE;
+            }
+        });
+    }
+
+    private void process(String absolutePath) {
+        try {
+            String sha256sum = DigestUtil.sha256sum(absolutePath);
+            FileMeta fileMeta = fileMetaMapper.findBySha256sum(sha256sum);
+            if (fileMeta != null) {
+                FileUtils.deleteQuietly(new File(absolutePath));
+            } else {
+                log.info("{} 在 db 中不存在", absolutePath);
+            }
+        } catch (IOException | NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void deleteFile() throws IOException {
+        String baseDir = "/home/reghao/mnt/porn/0.已完成";
+        baseDir = "/run/media/reghao/7c43343d-c1e2-4e68-bc18-89bd3f61b0c8/spider/porn/";
+        Path path = Path.of(baseDir);
+        walkDir(path);
+    }
 }