Skip to content

Commit 46fc045

Browse files
shameersss1steveloughran
authored andcommitted
HADOOP-19309: S3A: CopyFromLocalFile operation fails when the source file does not contain file scheme (#7113)
Contributed by Syed Shameerur Rahman
1 parent 3809627 commit 46fc045

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/CopyFromLocalOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public CopyFromLocalOperation(
130130
this.callbacks = callbacks;
131131
this.deleteSource = deleteSource;
132132
this.overwrite = overwrite;
133-
this.source = source;
133+
this.source = source.toUri().getScheme() == null ? new Path("file://", source) : source;
134134
this.destination = destination;
135135

136136
// Capacity of 1 is a safe default for now since transfer manager can also

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ACopyFromLocalFile.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.fs.s3a;
2020

2121
import java.io.File;
22+
import java.io.IOException;
2223
import java.util.Arrays;
2324
import java.util.Collection;
2425

@@ -107,4 +108,15 @@ public void testOnlyFromLocal() throws Throwable {
107108
intercept(IllegalArgumentException.class,
108109
() -> getFileSystem().copyFromLocalFile(true, true, dest, dest));
109110
}
111+
112+
@Test
113+
public void testCopyFromLocalWithNoFileScheme() throws IOException {
114+
describe("Copying from local file with no file scheme to remote s3 destination");
115+
File source = createTempFile("tempData");
116+
Path dest = path(getMethodName());
117+
118+
Path sourcePathWithOutScheme = new Path(source.toURI().getPath());
119+
assertNull(sourcePathWithOutScheme.toUri().getScheme());
120+
getFileSystem().copyFromLocalFile(true, true, sourcePathWithOutScheme, dest);
121+
}
110122
}

0 commit comments

Comments
 (0)