HADOOP-13188 S3A file-create should throw error rather than overwrite directories. Contributed by Steve Loughran
This commit is contained in:
parent
271e7bb00b
commit
b757eff30c
|
@ -598,9 +598,24 @@ public class S3AFileSystem extends FileSystem {
|
||||||
boolean overwrite, int bufferSize, short replication, long blockSize,
|
boolean overwrite, int bufferSize, short replication, long blockSize,
|
||||||
Progressable progress) throws IOException {
|
Progressable progress) throws IOException {
|
||||||
String key = pathToKey(f);
|
String key = pathToKey(f);
|
||||||
|
S3AFileStatus status = null;
|
||||||
|
try {
|
||||||
|
// get the status or throw an FNFE
|
||||||
|
status = getFileStatus(f);
|
||||||
|
|
||||||
|
// if the thread reaches here, there is something at the path
|
||||||
|
if (status.isDirectory()) {
|
||||||
|
// path references a directory: automatic error
|
||||||
|
throw new FileAlreadyExistsException(f + " is a directory");
|
||||||
|
}
|
||||||
|
if (!overwrite) {
|
||||||
|
// path references a file and overwrite is disabled
|
||||||
|
throw new FileAlreadyExistsException(f + " already exists");
|
||||||
|
}
|
||||||
|
LOG.debug("Overwriting file {}", f);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// this means the file is not found
|
||||||
|
|
||||||
if (!overwrite && exists(f)) {
|
|
||||||
throw new FileAlreadyExistsException(f + " already exists");
|
|
||||||
}
|
}
|
||||||
instrumentation.fileCreated();
|
instrumentation.fileCreated();
|
||||||
if (getConf().getBoolean(FAST_UPLOAD, DEFAULT_FAST_UPLOAD)) {
|
if (getConf().getBoolean(FAST_UPLOAD, DEFAULT_FAST_UPLOAD)) {
|
||||||
|
|
|
@ -30,9 +30,4 @@ public class TestS3AContractCreate extends AbstractContractCreateTest {
|
||||||
return new S3AContract(conf);
|
return new S3AContract(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void testOverwriteEmptyDirectory() throws Throwable {
|
|
||||||
ContractTestUtils.skip(
|
|
||||||
"blobstores can't distinguish empty directories from files");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue