Skip to content

Commit 76d0022

Browse files
authored
stage fix:keep the original directory structure (milvus-io#1483)
Signed-off-by: lentitude2tk <xushuang.hu@zilliz.com>
1 parent eb55214 commit 76d0022

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

sdk-bulkwriter/src/main/java/io/milvus/bulkwriter/StageOperation.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import java.io.File;
3737
import java.io.IOException;
38+
import java.nio.file.Path;
39+
import java.nio.file.Paths;
3840
import java.time.Instant;
3941
import java.util.ArrayList;
4042
import java.util.Date;
@@ -86,7 +88,7 @@ public StageUploadResult uploadFileToStage(String localDirOrFilePath) throws Exc
8688
File file = new File(localFilePath);
8789
long fileStartTime = System.currentTimeMillis();
8890
try {
89-
uploadLocalFileToStage(localFilePath);
91+
uploadLocalFileToStage(localFilePath, localDirOrFilePath);
9092
long bytes = processedBytes.addAndGet(file.length());
9193
long elapsed = System.currentTimeMillis() - fileStartTime;
9294
double percent = totalBytes == 0 ? 100.0 : (bytes * 100.0 / totalBytes);
@@ -145,10 +147,19 @@ private String convertDirPath(String inputPath) {
145147
return inputPath + "/";
146148
}
147149

148-
private String uploadLocalFileToStage(String localFilePath) throws Exception {
150+
private String uploadLocalFileToStage(String localFilePath, String rootPath) throws Exception {
149151
File file = new File(localFilePath);
150-
String fileName = file.getName();
151-
String remoteFilePath = applyStageResponse.getUploadPath() + fileName;
152+
Path filePath = file.toPath().toAbsolutePath();
153+
Path root = Paths.get(rootPath).toAbsolutePath();
154+
155+
String relativePath;
156+
if (root.toFile().isFile()) {
157+
relativePath = file.getName();
158+
} else {
159+
relativePath = root.relativize(filePath).toString().replace("\\", "/");
160+
}
161+
162+
String remoteFilePath = applyStageResponse.getUploadPath() + relativePath;
152163
putObject(file, remoteFilePath);
153164
return remoteFilePath;
154165
}

0 commit comments

Comments
 (0)