/** * Create the directory or check permissions if it already exists. * * The semantics of mkdirsWithExistsAndPermissionCheck method is different * from the mkdirs method provided in the Sun's java.io.File class in the * following way: * While creating the non-existent parent directories, this method checks for * the existence of those directories if the mkdir fails at any point (since * that directory might have just been created by some other process). * If both mkdir() and the exists() check fails for any seemingly * non-existent directory, then we signal an error; Sun's mkdir would signal * an error (return false) if a directory it is attempting to create already * exists or the mkdir fails. * * @param localFS local filesystem * @param dir directory to be created or checked * @param expected expected permission * @throws IOException */ static void mkdirsWithExistsAndPermissionCheck( LocalFileSystem localFS, Path dir, FsPermission expected) throws IOException { File directory = localFS.pathToFile(dir); boolean created = false; if (!directory.exists()) created = mkdirsWithExistsCheck(directory); if (created || !localFS.getFileStatus(dir).getPermission().equals(expected)) localFS.setPermission(dir, expected); }
/** * Get pin status of a file by checking the sticky bit. * @param localFS local file system * @param path path to be checked * @return true if the file is pinned with sticky bit * @throws IOException */ public boolean getPinning(LocalFileSystem localFS, Path path) throws IOException { boolean stickyBit = localFS.getFileStatus(path).getPermission().getStickyBit(); return stickyBit; }
/** * Set sticky bit on path to pin file. * @param localFS local file system * @param path path to be pinned with sticky bit * @throws IOException */ public void setPinning(LocalFileSystem localFS, Path path) throws IOException { FsPermission oldPermission = localFS.getFileStatus(path).getPermission(); FsPermission permission = new FsPermission(oldPermission.getUserAction(), oldPermission.getGroupAction(), oldPermission.getOtherAction(), true); localFS.setPermission(path, permission); }
String getGroup(LocalFileSystem fs, Path p) throws IOException { return fs.getFileStatus(p).getGroup(); } }
FsPermission getPermission(LocalFileSystem fs, Path p) throws IOException { return fs.getFileStatus(p).getPermission(); }
@Override public boolean getPinning(ExtendedBlock block) throws IOException { if (!blockPinningEnabled) { return false; } File f = getBlockFile(block); FileStatus fss = localFS.getFileStatus(new Path(f.getAbsolutePath())); return fss.getPermission().getStickyBit(); }
@Override public boolean getPinning(ExtendedBlock block) throws IOException { if (!blockPinningEnabled) { return false; } File f = getBlockFile(block); FileStatus fss = localFS.getFileStatus(new Path(f.getAbsolutePath())); return fss.getPermission().getStickyBit(); }
@Override public void setPinning(ExtendedBlock block) throws IOException { if (!blockPinningEnabled) { return; } File f = getBlockFile(block); Path p = new Path(f.getAbsolutePath()); FsPermission oldPermission = localFS.getFileStatus( new Path(f.getAbsolutePath())).getPermission(); //sticky bit is used for pinning purpose FsPermission permission = new FsPermission(oldPermission.getUserAction(), oldPermission.getGroupAction(), oldPermission.getOtherAction(), true); localFS.setPermission(p, permission); }
@Override public void setPinning(ExtendedBlock block) throws IOException { if (!blockPinningEnabled) { return; } File f = getBlockFile(block); Path p = new Path(f.getAbsolutePath()); FsPermission oldPermission = localFS.getFileStatus( new Path(f.getAbsolutePath())).getPermission(); //sticky bit is used for pinning purpose FsPermission permission = new FsPermission(oldPermission.getUserAction(), oldPermission.getGroupAction(), oldPermission.getOtherAction(), true); localFS.setPermission(p, permission); }
String getGroup(LocalFileSystem fs, Path p) throws IOException { return fs.getFileStatus(p).getGroup(); } }
String getGroup(LocalFileSystem fs, Path p) throws IOException { return fs.getFileStatus(p).getGroup(); } }
FsPermission getPermission(LocalFileSystem fs, Path p) throws IOException { return fs.getFileStatus(p).getPermission(); }
FsPermission getPermission(LocalFileSystem fs, Path p) throws IOException { return fs.getFileStatus(p).getPermission(); }
private String readFile(String out) throws IOException { Path path = new Path(out); FileStatus stat = lfs.getFileStatus(path); FSDataInputStream in = lfs.open(path); byte[] buffer = new byte[(int)stat.getLen()]; in.readFully(buffer); in.close(); lfs.delete(path, false); return new String(buffer); }
private String readFile(String out) throws IOException { Path path = new Path(out); FileStatus stat = lfs.getFileStatus(path); FSDataInputStream in = lfs.open(path); byte[] buffer = new byte[(int)stat.getLen()]; in.readFully(buffer); in.close(); lfs.delete(path, false); return new String(buffer); }
@Test(timeout = 1000) public void testPathEscapes() throws IOException { Path path = new Path(TEST_ROOT_DIR, "foo%bar"); writeFile(fileSys, path, 1); FileStatus status = fileSys.getFileStatus(path); assertEquals(path.makeQualified(fileSys), status.getPath()); cleanupFile(fileSys, path); }
@Test(timeout = 1000) public void testPathEscapes() throws IOException { Path path = new Path(TEST_ROOT_DIR, "foo%bar"); writeFile(fileSys, path, 1); FileStatus status = fileSys.getFileStatus(path); assertEquals(path.makeQualified(fileSys), status.getPath()); cleanupFile(fileSys, path); }
@Test(timeout = 1000) public void testSetTimes() throws Exception { Path path = new Path(TEST_ROOT_DIR, "set-times"); writeFile(fileSys, path, 1); // test only to the nearest second, as the raw FS may not // support millisecond timestamps long newModTime = 12345000; FileStatus status = fileSys.getFileStatus(path); assertTrue("check we're actually changing something", newModTime != status.getModificationTime()); long accessTime = status.getAccessTime(); fileSys.setTimes(path, newModTime, -1); status = fileSys.getFileStatus(path); assertEquals(newModTime, status.getModificationTime()); assertEquals(accessTime, status.getAccessTime()); }
@Test public void testSetPermissionCrc() throws Exception { FileSystem rawFs = localFs.getRawFileSystem(); Path p = new Path(TEST_ROOT_DIR, "testCrcPermissions"); localFs.createNewFile(p); Path crc = localFs.getChecksumFile(p); assert(rawFs.exists(crc)); for (short mode : Arrays.asList((short)0666, (short)0660, (short)0600)) { FsPermission perm = new FsPermission(mode); localFs.setPermission(p, perm); assertEquals(perm, localFs.getFileStatus(p).getPermission()); assertEquals(perm, rawFs.getFileStatus(crc).getPermission()); } } }
@Test public void testSetPermissionCrc() throws Exception { FileSystem rawFs = localFs.getRawFileSystem(); Path p = new Path(TEST_ROOT_DIR, "testCrcPermissions"); localFs.createNewFile(p); Path crc = localFs.getChecksumFile(p); assert(rawFs.exists(crc)); for (short mode : Arrays.asList((short)0666, (short)0660, (short)0600)) { FsPermission perm = new FsPermission(mode); localFs.setPermission(p, perm); assertEquals(perm, localFs.getFileStatus(p).getPermission()); assertEquals(perm, rawFs.getFileStatus(crc).getPermission()); } } }