HADOOP-6886. LocalFileSystem Needs createNonRecursive API. Contributed by Nicolas Spiegelberg and Eli Collins
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1212073 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dec526076f
commit
2deaca4415
@ -164,6 +164,9 @@ Release 0.23.1 - Unreleased
|
|||||||
HADOOP-6840. Support non-recursive create() in FileSystem and
|
HADOOP-6840. Support non-recursive create() in FileSystem and
|
||||||
SequenceFile.Writer. (jitendra and eli via eli)
|
SequenceFile.Writer. (jitendra and eli via eli)
|
||||||
|
|
||||||
|
HADOOP-6886. LocalFileSystem Needs createNonRecursive API.
|
||||||
|
(Nicolas Spiegelberg and eli via eli)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.zip.CRC32;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -31,7 +29,6 @@
|
|||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
import org.apache.hadoop.util.Progressable;
|
import org.apache.hadoop.util.Progressable;
|
||||||
import org.apache.hadoop.util.PureJavaCrc32;
|
import org.apache.hadoop.util.PureJavaCrc32;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Abstract Checksumed FileSystem.
|
* Abstract Checksumed FileSystem.
|
||||||
@ -389,9 +386,22 @@ protected void writeChunk(byte[] b, int offset, int len, byte[] checksum)
|
|||||||
public FSDataOutputStream create(Path f, FsPermission permission,
|
public FSDataOutputStream create(Path f, FsPermission permission,
|
||||||
boolean overwrite, int bufferSize, short replication, long blockSize,
|
boolean overwrite, int bufferSize, short replication, long blockSize,
|
||||||
Progressable progress) throws IOException {
|
Progressable progress) throws IOException {
|
||||||
|
return create(f, permission, overwrite, true, bufferSize,
|
||||||
|
replication, blockSize, progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FSDataOutputStream create(Path f, FsPermission permission,
|
||||||
|
boolean overwrite, boolean createParent, int bufferSize,
|
||||||
|
short replication, long blockSize,
|
||||||
|
Progressable progress) throws IOException {
|
||||||
Path parent = f.getParent();
|
Path parent = f.getParent();
|
||||||
if (parent != null && !mkdirs(parent)) {
|
if (parent != null) {
|
||||||
throw new IOException("Mkdirs failed to create " + parent);
|
if (!createParent && !exists(parent)) {
|
||||||
|
throw new FileNotFoundException("Parent directory doesn't exist: "
|
||||||
|
+ parent);
|
||||||
|
} else if (!mkdirs(parent)) {
|
||||||
|
throw new IOException("Mkdirs failed to create " + parent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final FSDataOutputStream out = new FSDataOutputStream(
|
final FSDataOutputStream out = new FSDataOutputStream(
|
||||||
new ChecksumFSOutputSummer(this, f, overwrite, bufferSize, replication,
|
new ChecksumFSOutputSummer(this, f, overwrite, bufferSize, replication,
|
||||||
@ -402,6 +412,15 @@ public FSDataOutputStream create(Path f, FsPermission permission,
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
|
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,
|
||||||
|
boolean overwrite, int bufferSize, short replication, long blockSize,
|
||||||
|
Progressable progress) throws IOException {
|
||||||
|
return create(f, permission, overwrite, false, bufferSize, replication,
|
||||||
|
blockSize, progress);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set replication for an existing file.
|
* Set replication for an existing file.
|
||||||
* Implement the abstract <tt>setReplication</tt> of <tt>FileSystem</tt>
|
* Implement the abstract <tt>setReplication</tt> of <tt>FileSystem</tt>
|
||||||
|
@ -871,10 +871,10 @@ public FSDataOutputStream createNonRecursive(Path f,
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,
|
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,
|
||||||
boolean overwrite,
|
boolean overwrite, int bufferSize, short replication, long blockSize,
|
||||||
int bufferSize, short replication, long blockSize,
|
|
||||||
Progressable progress) throws IOException {
|
Progressable progress) throws IOException {
|
||||||
throw new IOException("createNonRecursive unsupported for this filesystem");
|
throw new IOException("createNonRecursive unsupported for this filesystem "
|
||||||
|
+ this.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
@ -238,9 +237,16 @@ public FSDataOutputStream append(Path f, int bufferSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize,
|
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize,
|
||||||
short replication, long blockSize, Progressable progress)
|
short replication, long blockSize, Progressable progress)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
return create(f, overwrite, true, bufferSize, replication, blockSize, progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FSDataOutputStream create(Path f, boolean overwrite,
|
||||||
|
boolean createParent, int bufferSize, short replication, long blockSize,
|
||||||
|
Progressable progress) throws IOException {
|
||||||
if (exists(f) && !overwrite) {
|
if (exists(f) && !overwrite) {
|
||||||
throw new IOException("File already exists: "+f);
|
throw new IOException("File already exists: "+f);
|
||||||
}
|
}
|
||||||
@ -264,6 +270,18 @@ public FSDataOutputStream create(Path f, FsPermission permission,
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
|
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,
|
||||||
|
boolean overwrite,
|
||||||
|
int bufferSize, short replication, long blockSize,
|
||||||
|
Progressable progress) throws IOException {
|
||||||
|
FSDataOutputStream out = create(f,
|
||||||
|
overwrite, false, bufferSize, replication, blockSize, progress);
|
||||||
|
setPermission(f, permission);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean rename(Path src, Path dst) throws IOException {
|
public boolean rename(Path src, Path dst) throws IOException {
|
||||||
if (pathToFile(src).renameTo(pathToFile(dst))) {
|
if (pathToFile(src).renameTo(pathToFile(dst))) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user