public virtual void TestBackwardCompatibility() { // Test 1 - old configuration key with decimal // umask value should be handled when set using // FSPermission.setUMask() API FsPermission perm = new FsPermission((short)18); Configuration conf = new Configuration(); FsPermission.SetUMask(conf, perm); NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort()); // Test 2 - old configuration key set with decimal // umask value should be handled perm = new FsPermission((short)18); conf = new Configuration(); conf.Set(FsPermission.DeprecatedUmaskLabel, "18"); NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort()); // Test 3 - old configuration key overrides the new one conf = new Configuration(); conf.Set(FsPermission.DeprecatedUmaskLabel, "18"); conf.Set(FsPermission.UmaskLabel, "000"); NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort()); // Test 4 - new configuration key is handled conf = new Configuration(); conf.Set(FsPermission.UmaskLabel, "022"); NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort()); }
/// <exception cref="System.IO.IOException"/> private void CreateDir(FileSystem fs, Path path, FsPermission fsPerm) { FsPermission dirPerm = new FsPermission(fsPerm); fs.Mkdirs(path, dirPerm); FsPermission umask = FsPermission.GetUMask(fs.GetConf()); if (!dirPerm.Equals(dirPerm.ApplyUMask(umask))) { fs.SetPermission(path, new FsPermission(fsPerm)); } }
/// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/> /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/> /// <exception cref="System.IO.FileNotFoundException"/> /// <exception cref="Org.Apache.Hadoop.FS.ParentNotDirectoryException"/> /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/> /// <exception cref="System.IO.IOException"/> public override FSDataOutputStream Create(Path f, EnumSet <CreateFlag> createFlag, params Options.CreateOpts[] opts) { // Need to translate the FileContext-style options into FileSystem-style // Permissions with umask Options.CreateOpts.Perms permOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.Perms >(opts); FsPermission umask = FsPermission.GetUMask(fs.GetConf()); FsPermission permission = (permOpt != null) ? permOpt.GetValue() : FsPermission.GetFileDefault ().ApplyUMask(umask); permission = permission.ApplyUMask(umask); // Overwrite bool overwrite = createFlag.Contains(CreateFlag.Overwrite); // bufferSize int bufferSize = fs.GetConf().GetInt(CommonConfigurationKeysPublic.IoFileBufferSizeKey , CommonConfigurationKeysPublic.IoFileBufferSizeDefault); Options.CreateOpts.BufferSize bufOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.BufferSize >(opts); bufferSize = (bufOpt != null) ? bufOpt.GetValue() : bufferSize; // replication short replication = fs.GetDefaultReplication(f); Options.CreateOpts.ReplicationFactor repOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.ReplicationFactor >(opts); replication = (repOpt != null) ? repOpt.GetValue() : replication; // blockSize long blockSize = fs.GetDefaultBlockSize(f); Options.CreateOpts.BlockSize blockOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.BlockSize >(opts); blockSize = (blockOpt != null) ? blockOpt.GetValue() : blockSize; // Progressable Progressable progress = null; Options.CreateOpts.Progress progressOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.Progress >(opts); progress = (progressOpt != null) ? progressOpt.GetValue() : progress; return(fs.Create(f, permission, overwrite, bufferSize, replication, blockSize, progress )); }
/// <summary>Test LocalFileSystem.setPermission</summary> /// <exception cref="System.IO.IOException"/> public virtual void TestLocalFSsetPermission() { if (Path.Windows) { System.Console.Out.WriteLine("Cannot run test for Windows"); return; } Configuration conf = new Configuration(); LocalFileSystem localfs = FileSystem.GetLocal(conf); string filename = "foo"; Path f = WriteFile(localfs, filename); try { FsPermission initialPermission = GetPermission(localfs, f); System.Console.Out.WriteLine(filename + ": " + initialPermission); Assert.Equal(FsPermission.GetFileDefault().ApplyUMask(FsPermission .GetUMask(conf)), initialPermission); } catch (Exception e) { System.Console.Out.WriteLine(StringUtils.StringifyException(e)); System.Console.Out.WriteLine("Cannot run test"); return; } try { // create files and manipulate them. FsPermission all = new FsPermission((short)0x1ff); FsPermission none = new FsPermission((short)0); localfs.SetPermission(f, none); Assert.Equal(none, GetPermission(localfs, f)); localfs.SetPermission(f, all); Assert.Equal(all, GetPermission(localfs, f)); } finally { CleanupFile(localfs, f); } }
// just in case copyBytes didn't // tag created files as temp files /// <exception cref="System.IO.IOException"/> internal virtual FSDataOutputStream Create(PathData item, bool lazyPersist) { try { if (lazyPersist) { EnumSet <CreateFlag> createFlags = EnumSet.Of(CreateFlag.Create, CreateFlag.LazyPersist ); return(Create(item.path, FsPermission.GetFileDefault().ApplyUMask(FsPermission.GetUMask (GetConf())), createFlags, GetConf().GetInt("io.file.buffer.size", 4096), lazyPersist ? 1 : GetDefaultReplication(item.path), GetDefaultBlockSize(), null, null)); } else { return(Create(item.path, true)); } } finally { // might have been created but stream was interrupted DeleteOnExit(item.path); } }