/// <summary>Use the command chmod to set permission.</summary> /// <exception cref="System.IO.IOException"/> public override void SetPermission(Path p, FsPermission permission) { if (NativeIO.IsAvailable()) { NativeIO.POSIX.Chmod(PathToFile(p).GetCanonicalPath(), permission.ToShort()); } else { string perm = string.Format("%04o", permission.ToShort()); Shell.ExecCommand(Shell.GetSetPermissionCommand(perm, false, FileUtil.MakeShellPath (PathToFile(p), true))); } }
internal override void SetPermission(FsPermission permission) { short mode = permission.ToShort(); UpdatePermissionStatus(INodeWithAdditionalFields.PermissionStatusFormat.Mode, mode ); }
/// <exception cref="System.IO.IOException"/> public override void SetPermission(Path p, FsPermission permission) { if (Log.IsDebugEnabled()) { Log.Debug(string.Format("EFS:setPermission: %s %s", p, permission)); } WindowsSecureContainerExecutor.Native.Elevated.Chmod(p, permission.ToShort()); }
/// <exception cref="System.IO.IOException"/> private void AssertPermissions(FilePath f, int expected) { FileSystem localfs = FileSystem.GetLocal(new Configuration()); FsPermission perms = localfs.GetFileStatus(new Path(f.GetAbsolutePath())).GetPermission (); Assert.Equal(expected, perms.ToShort()); }
/// <summary>Asserts the value of the FsPermission bits on the inode of a specific path. /// </summary> /// <param name="fs">FileSystem to use for check</param> /// <param name="pathToCheck">Path inode to check</param> /// <param name="perm">short expected permission bits</param> /// <exception cref="System.IO.IOException">thrown if there is an I/O error</exception> public static void AssertPermission(FileSystem fs, Path pathToCheck, short perm) { short filteredPerm = (short)(perm & 0x3ff); FsPermission fsPermission = fs.GetFileStatus(pathToCheck).GetPermission(); NUnit.Framework.Assert.AreEqual(filteredPerm, fsPermission.ToShort()); NUnit.Framework.Assert.AreEqual(((perm & (1 << 12)) != 0), fsPermission.GetAclBit ()); }
/// <exception cref="System.IO.IOException"/> internal static FsPermission CheckPermission(FileSystem fs, string path, FsPermission expected) { FileStatus s = fs.GetFileStatus(new Path(path)); Log.Info(s.GetPath() + ": " + s.IsDirectory() + " " + s.GetPermission() + ":" + s .GetOwner() + ":" + s.GetGroup()); if (expected != null) { NUnit.Framework.Assert.AreEqual(expected, s.GetPermission()); NUnit.Framework.Assert.AreEqual(expected.ToShort(), s.GetPermission().ToShort()); } return(s.GetPermission()); }
/// <exception cref="System.IO.IOException"/> protected internal virtual bool MkOneDirWithMode(Path p, FilePath p2f, FsPermission permission) { if (permission == null) { return(p2f.Mkdir()); } else { if (Shell.Windows && NativeIO.IsAvailable()) { try { NativeIO.Windows.CreateDirectoryWithMode(p2f, permission.ToShort()); return(true); } catch (IOException e) { if (Log.IsDebugEnabled()) { Log.Debug(string.Format("NativeIO.createDirectoryWithMode error, path = %s, mode = %o" , p2f, permission.ToShort()), e); } return(false); } } else { bool b = p2f.Mkdir(); if (b) { SetPermission(p, permission); } return(b); } } }
// not listable /// <exception cref="System.Exception"/> private void _checkDirs(bool isDir, FsPermission perm, bool success) { FilePath localDir = FilePath.CreateTempFile("test", "tmp"); if (isDir) { localDir.Delete(); localDir.Mkdir(); } Shell.ExecCommand(Shell.GetSetPermissionCommand(string.Format("%04o", perm.ToShort ()), false, localDir.GetAbsolutePath())); try { DiskChecker.CheckDir(FileSystem.GetLocal(new Configuration()), new Path(localDir. GetAbsolutePath()), perm); Assert.True("checkDir success", success); } catch (DiskChecker.DiskErrorException) { NUnit.Framework.Assert.IsFalse("checkDir success", success); } localDir.Delete(); }
public virtual void TestCreate() { Configuration conf = new HdfsConfiguration(); conf.SetBoolean(DFSConfigKeys.DfsPermissionsEnabledKey, true); conf.Set(FsPermission.UmaskLabel, "000"); MiniDFSCluster cluster = null; FileSystem fs = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(3).Build(); cluster.WaitActive(); fs = FileSystem.Get(conf); FsPermission rootPerm = CheckPermission(fs, "/", null); FsPermission inheritPerm = FsPermission.CreateImmutable((short)(rootPerm.ToShort( ) | 0xc0)); FsPermission dirPerm = new FsPermission((short)0x1ff); fs.Mkdirs(new Path("/a1/a2/a3"), dirPerm); CheckPermission(fs, "/a1", dirPerm); CheckPermission(fs, "/a1/a2", dirPerm); CheckPermission(fs, "/a1/a2/a3", dirPerm); dirPerm = new FsPermission((short)0x53); FsPermission permission = FsPermission.CreateImmutable((short)(dirPerm.ToShort() | 0xc0)); fs.Mkdirs(new Path("/aa/1/aa/2/aa/3"), dirPerm); CheckPermission(fs, "/aa/1", permission); CheckPermission(fs, "/aa/1/aa/2", permission); CheckPermission(fs, "/aa/1/aa/2/aa/3", dirPerm); FsPermission filePerm = new FsPermission((short)0x124); Path p = new Path("/b1/b2/b3.txt"); FSDataOutputStream @out = fs.Create(p, filePerm, true, conf.GetInt(CommonConfigurationKeys .IoFileBufferSizeKey, 4096), fs.GetDefaultReplication(p), fs.GetDefaultBlockSize (p), null); @out.Write(123); @out.Close(); CheckPermission(fs, "/b1", inheritPerm); CheckPermission(fs, "/b1/b2", inheritPerm); CheckPermission(fs, "/b1/b2/b3.txt", filePerm); conf.Set(FsPermission.UmaskLabel, "022"); permission = FsPermission.CreateImmutable((short)0x1b6); FileSystem.Mkdirs(fs, new Path("/c1"), new FsPermission(permission)); FileSystem.Create(fs, new Path("/c1/c2.txt"), new FsPermission(permission)); CheckPermission(fs, "/c1", permission); CheckPermission(fs, "/c1/c2.txt", permission); } finally { try { if (fs != null) { fs.Close(); } } catch (Exception e) { Log.Error(StringUtils.StringifyException(e)); } try { if (cluster != null) { cluster.Shutdown(); } } catch (Exception e) { Log.Error(StringUtils.StringifyException(e)); } } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Sharpen.URISyntaxException"/> /// <exception cref="System.Exception"/> public virtual void TestDownload() { Configuration conf = new Configuration(); conf.Set(CommonConfigurationKeys.FsPermissionsUmaskKey, "077"); FileContext files = FileContext.GetLocalFSFileContext(conf); Path basedir = files.MakeQualified(new Path("target", typeof(TestFSDownload).Name )); files.Mkdir(basedir, null, true); conf.SetStrings(typeof(TestFSDownload).FullName, basedir.ToString()); IDictionary <LocalResource, LocalResourceVisibility> rsrcVis = new Dictionary <LocalResource , LocalResourceVisibility>(); Random rand = new Random(); long sharedSeed = rand.NextLong(); rand.SetSeed(sharedSeed); System.Console.Out.WriteLine("SEED: " + sharedSeed); IDictionary <LocalResource, Future <Path> > pending = new Dictionary <LocalResource, Future <Path> >(); ExecutorService exec = Executors.NewSingleThreadExecutor(); LocalDirAllocator dirs = new LocalDirAllocator(typeof(TestFSDownload).FullName); int[] sizes = new int[10]; for (int i = 0; i < 10; ++i) { sizes[i] = rand.Next(512) + 512; LocalResourceVisibility vis = LocalResourceVisibility.Private; if (i % 2 == 1) { vis = LocalResourceVisibility.Application; } Path p = new Path(basedir, string.Empty + i); LocalResource rsrc = CreateFile(files, p, sizes[i], rand, vis); rsrcVis[rsrc] = vis; Path destPath = dirs.GetLocalPathForWrite(basedir.ToString(), sizes[i], conf); destPath = new Path(destPath, System.Convert.ToString(uniqueNumberGenerator.IncrementAndGet ())); FSDownload fsd = new FSDownload(files, UserGroupInformation.GetCurrentUser(), conf , destPath, rsrc); pending[rsrc] = exec.Submit(fsd); } exec.Shutdown(); while (!exec.AwaitTermination(1000, TimeUnit.Milliseconds)) { } foreach (Future <Path> path in pending.Values) { NUnit.Framework.Assert.IsTrue(path.IsDone()); } try { foreach (KeyValuePair <LocalResource, Future <Path> > p in pending) { Path localized = p.Value.Get(); NUnit.Framework.Assert.AreEqual(sizes[Sharpen.Extensions.ValueOf(localized.GetName ())], p.Key.GetSize()); FileStatus status = files.GetFileStatus(localized.GetParent()); FsPermission perm = status.GetPermission(); NUnit.Framework.Assert.AreEqual("Cache directory permissions are incorrect", new FsPermission((short)0x1ed), perm); status = files.GetFileStatus(localized); perm = status.GetPermission(); System.Console.Out.WriteLine("File permission " + perm + " for rsrc vis " + p.Key .GetVisibility().ToString()); System.Diagnostics.Debug.Assert((rsrcVis.Contains(p.Key))); NUnit.Framework.Assert.IsTrue("Private file should be 500", perm.ToShort() == FSDownload .PrivateFilePerms.ToShort()); } } catch (ExecutionException e) { throw new IOException("Failed exec", e); } }
public override string ToString() { return(new StringBuilder().Append("{").Append("poolName:").Append(poolName).Append (", ownerName:").Append(ownerName).Append(", groupName:").Append(groupName).Append (", mode:").Append((mode == null) ? "null" : string.Format("0%03o", mode.ToShort ())).Append(", limit:").Append(limit).Append(", maxRelativeExpiryMs:").Append(maxRelativeExpiryMs ).Append("}").ToString()); }
private string ToString(FsPermission permission) { return(string.Format("%o", permission.ToShort())); }
/// <exception cref="System.IO.IOException"/> private LocalFSFileOutputStream(RawLocalFileSystem _enclosing, Path f, bool append , FsPermission permission) { this._enclosing = _enclosing; FilePath file = this._enclosing.PathToFile(f); if (permission == null) { this.fos = new FileOutputStream(file, append); } else { if (Shell.Windows && NativeIO.IsAvailable()) { this.fos = NativeIO.Windows.CreateFileOutputStreamWithMode(file, append, permission .ToShort()); } else { this.fos = new FileOutputStream(file, append); bool success = false; try { this._enclosing.SetPermission(f, permission); success = true; } finally { if (!success) { IOUtils.Cleanup(FileSystem.Log, this.fos); } } } } }
/// <summary>Constructor.</summary> /// <param name="value">the parameter value.</param> public PermissionParam(FsPermission value) : base(Domain, value == null ? null : value.ToShort(), null, null) { }
/// <summary>Constructs a new FsPermissionExtension based on the given FsPermission.</summary> /// <param name="perm">FsPermission containing permission bits</param> public FsPermissionExtension(FsPermission perm, bool hasAcl, bool isEncrypted) : base(perm.ToShort()) { aclBit = hasAcl; encryptedBit = isEncrypted; }