public ChRootedFs(final AbstractFileSystem fs, final Path theRoot) throws URISyntaxException { super(fs.getUri(), fs.getUri().getScheme(), false, fs.getUriDefaultPort()); myFs = fs; myFs.checkPath(theRoot); chRootPathPart = new Path(myFs.getUriPath(theRoot)); chRootPathPartString = chRootPathPart.toUri().getPath(); /* * We are making URI include the chrootedPath: e.g. file:///chrootedPath. * This is questionable since Path#makeQualified(uri, path) ignores * the pathPart of a uri. Since this class is internal we can ignore * this issue but if we were to make it external then this needs * to be resolved. */ // Handle the two cases: // scheme:/// and scheme://authority/ myUri = new URI(myFs.getUri().toString() + (myFs.getUri().getAuthority() == null ? "" : Path.SEPARATOR) + chRootPathPart.toUri().getPath().substring(1)); super.checkPath(theRoot); }
@Override public FileStatus[] next(final AbstractFileSystem fs, final Path p) throws IOException, UnresolvedLinkException { return fs.listStatus(p); } }.resolve(FileContext.this, absF);
@Override public Path next(final AbstractFileSystem fs, final Path p) throws IOException, UnresolvedLinkException { return fs.resolvePath(p); } }.resolve(this, f);
/** * Constructor to be called by subclasses. * * @param uri for this file system. * @param supportedScheme the scheme supported by the implementor * @param authorityNeeded if true then theURI must have authority, if false * then the URI must have null authority. * * @throws URISyntaxException <code>uri</code> has syntax error */ public AbstractFileSystem(final URI uri, final String supportedScheme, final boolean authorityNeeded, final int defaultPort) throws URISyntaxException { myUri = getUri(uri, supportedScheme, authorityNeeded, defaultPort); statistics = getStatistics(uri); }
protected FilterFs(AbstractFileSystem fs) throws URISyntaxException { super(fs.getUri(), fs.getUri().getScheme(), false, fs.getUriDefaultPort()); myFs = fs; }
@Override public URI getUri() { return myFs.getUri(); }
private void testDefaultUriInternal(String defaultUri) throws UnsupportedFileSystemException { final Configuration conf = new Configuration(); FileSystem.setDefaultUri(conf, defaultUri); final AbstractFileSystem ftpFs = AbstractFileSystem.get(FTP_URI_NO_PORT, conf); Assert.assertEquals(FTP_URI_WITH_PORT, ftpFs.getUri()); }
try (FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()))) { os.write(new byte[1024 * 1024]); FileStatus status = fs.getFileStatus(file); long modificationTime = now - 5 * 60 * 1000; fs.setTimes(file, modificationTime, accessTime); status = fs.getFileStatus(file); assertEquals(accessTime, status.getAccessTime()); assertEquals(modificationTime, status.getModificationTime()); FileStatus[] files = fs.listStatus(new Path("/"));
@Override public boolean supportsSymlinks() { return myFs.supportsSymlinks(); }
AbstractFileSystem fs = AbstractFileSystem.get(new URI(igfsScheme()), job.getConfiguration()); for (FileStatus file : fs.listStatus(outDir)) { X.printerrln("__ file: " + file); continue; FSDataInputStream in = fs.open(file.getPath());
@Override public FileStatus next(final AbstractFileSystem fs, final Path p) throws IOException, UnresolvedLinkException { FileStatus fi = fs.getFileLinkStatus(p); if (fi.isSymlink()) { fi.setSymlink(FSLinkResolver.qualifySymlinkTarget(fs.getUri(), p, fi.getSymlink())); } return fi; } }.resolve(this, absF);
@Override public FSDataInputStream next(final AbstractFileSystem fs, final Path p) throws IOException, UnresolvedLinkException { return fs.open(p); } }.resolve(this, absF);
fs.mkdir(dir, FsPermission.getDefault(), true); FileStatus[] list = fs.listStatus(dir); fs.mkdir(subDir, FsPermission.getDefault(), true); FSDataOutputStream fos = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())); list = fs.listStatus(dir); list = fs.listStatus(file);
/** * Deletes all files from the given file system. * * @param fs The file system to clean up. * @throws IOException On error. */ public static void clear(AbstractFileSystem fs) throws IOException { // Delete root contents: FileStatus[] statuses = fs.listStatus(new Path("/")); if (statuses != null) { for (FileStatus stat: statuses) fs.delete(stat.getPath(), true); } }
/** * Return a set of server default configuration values based on path. * @param f path to fetch server defaults * @return server default configuration values for path * @throws IOException an I/O error occurred */ public FsServerDefaults getServerDefaults(final Path f) throws IOException { return getServerDefaults(); }
@Override public boolean isValidName(String src) { return myFs.isValidName(src); }
FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, UnresolvedLinkException, IOException { checkPath(f); int bufferSize = -1; short replication = -1; FsServerDefaults ssDef = getServerDefaults(f); if (ssDef.getBlockSize() % ssDef.getBytesPerChecksum() != 0) { throw new IOException("Internal error: default blockSize is" + return this.createInternal(f, createFlag, permission, bufferSize, replication, blockSize, progress, checksumOpt, createParent);
/** @throws Exception If failed. */ @Test public void testDeleteIfDirectoryPathExists() throws Exception { Path fsHome = new Path(primaryFsUri); Path dir = new Path(fsHome, "/someDir1/someDir2/someDir3"); FSDataOutputStream os = fs.create(dir, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())); os.close(); assertTrue(fs.delete(dir, false)); assertPathDoesNotExist(fs, dir); }
/** @throws Exception If failed. */ @Test public void testOpen() throws Exception { Path fsHome = new Path(primaryFsUri); Path file = new Path(fsHome, "someFile"); int cnt = 2 * 1024; try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()))) { for (long i = 0; i < cnt; i++) out.writeLong(i); } assertEquals(getClientFsUser(), fs.getFileStatus(file).getOwner()); try (FSDataInputStream in = fs.open(file, 1024)) { for (long i = 0; i < cnt; i++) assertEquals(i, in.readLong()); } }