Beispiel #1
0
        /// <summary>Validates the toString method for FileStatus.</summary>
        /// <param name="fileStatus">FileStatus to be validated</param>
        /// <exception cref="System.IO.IOException"/>
        private void ValidateToString(FileStatus fileStatus)
        {
            StringBuilder expected = new StringBuilder();

            expected.Append("FileStatus{");
            expected.Append("path=").Append(fileStatus.GetPath()).Append("; ");
            expected.Append("isDirectory=").Append(fileStatus.IsDirectory()).Append("; ");
            if (!fileStatus.IsDirectory())
            {
                expected.Append("length=").Append(fileStatus.GetLen()).Append("; ");
                expected.Append("replication=").Append(fileStatus.GetReplication()).Append("; ");
                expected.Append("blocksize=").Append(fileStatus.GetBlockSize()).Append("; ");
            }
            expected.Append("modification_time=").Append(fileStatus.GetModificationTime()).Append
                ("; ");
            expected.Append("access_time=").Append(fileStatus.GetAccessTime()).Append("; ");
            expected.Append("owner=").Append(fileStatus.GetOwner()).Append("; ");
            expected.Append("group=").Append(fileStatus.GetGroup()).Append("; ");
            expected.Append("permission=").Append(fileStatus.GetPermission()).Append("; ");
            if (fileStatus.IsSymlink())
            {
                expected.Append("isSymlink=").Append(true).Append("; ");
                expected.Append("symlink=").Append(fileStatus.GetSymlink()).Append("}");
            }
            else
            {
                expected.Append("isSymlink=").Append(false).Append("}");
            }
            Assert.Equal(expected.ToString(), fileStatus.ToString());
        }
Beispiel #2
0
        private FileStatus DeprecatedGetFileLinkStatusInternal(Path f)
        {
            string target = FileUtil.ReadLink(new FilePath(f.ToString()));

            try
            {
                FileStatus fs = GetFileStatus(f);
                // If f refers to a regular file or directory
                if (target.IsEmpty())
                {
                    return(fs);
                }
                // Otherwise f refers to a symlink
                return(new FileStatus(fs.GetLen(), false, fs.GetReplication(), fs.GetBlockSize(),
                                      fs.GetModificationTime(), fs.GetAccessTime(), fs.GetPermission(), fs.GetOwner(),
                                      fs.GetGroup(), new Path(target), f));
            }
            catch (FileNotFoundException e)
            {
                /* The exists method in the File class returns false for dangling
                 * links so we can get a FileNotFoundException for links that exist.
                 * It's also possible that we raced with a delete of the link. Use
                 * the readBasicFileAttributes method in java.nio.file.attributes
                 * when available.
                 */
                if (!target.IsEmpty())
                {
                    return(new FileStatus(0, false, 0, 0, 0, 0, FsPermission.GetDefault(), string.Empty
                                          , string.Empty, new Path(target), f));
                }
                // f refers to a file or directory that does not exist
                throw;
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestSetTimes()
        {
            Path path = new Path(TestRootDir, "set-times");

            FileSystemTestHelper.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);

            Assert.True("check we're actually changing something", newModTime
                        != status.GetModificationTime());
            long accessTime = status.GetAccessTime();

            fileSys.SetTimes(path, newModTime, -1);
            status = fileSys.GetFileStatus(path);
            Assert.Equal(newModTime, status.GetModificationTime());
            Assert.Equal(accessTime, status.GetAccessTime());
        }
 /// <summary>Constructor</summary>
 /// <param name="stat">a file status</param>
 /// <param name="locations">a file's block locations</param>
 /// <exception cref="System.IO.IOException"/>
 public LocatedFileStatus(FileStatus stat, BlockLocation[] locations)
     : this(stat.GetLen(), stat.IsDirectory(), stat.GetReplication(), stat.GetBlockSize
                (), stat.GetModificationTime(), stat.GetAccessTime(), stat.GetPermission(), stat
            .GetOwner(), stat.GetGroup(), null, stat.GetPath(), locations)
 {
     if (stat.IsSymlink())
     {
         SetSymlink(stat.GetSymlink());
     }
 }
Beispiel #5
0
 /// <summary>Validate the accessors for FileStatus.</summary>
 /// <param name="fileStatus">FileStatus to checked</param>
 /// <param name="length">expected length</param>
 /// <param name="isdir">expected isDirectory</param>
 /// <param name="replication">expected replication</param>
 /// <param name="blocksize">expected blocksize</param>
 /// <param name="mtime">expected modification time</param>
 /// <param name="atime">expected access time</param>
 /// <param name="permission">expected permission</param>
 /// <param name="owner">expected owner</param>
 /// <param name="group">expected group</param>
 /// <param name="symlink">expected symlink</param>
 /// <param name="path">expected path</param>
 /// <exception cref="System.IO.IOException"/>
 private void ValidateAccessors(FileStatus fileStatus, long length, bool isdir, int
                                replication, long blocksize, long mtime, long atime, FsPermission permission, string
                                owner, string group, Path symlink, Path path)
 {
     Assert.Equal(length, fileStatus.GetLen());
     Assert.Equal(isdir, fileStatus.IsDirectory());
     Assert.Equal(replication, fileStatus.GetReplication());
     Assert.Equal(blocksize, fileStatus.GetBlockSize());
     Assert.Equal(mtime, fileStatus.GetModificationTime());
     Assert.Equal(atime, fileStatus.GetAccessTime());
     Assert.Equal(permission, fileStatus.GetPermission());
     Assert.Equal(owner, fileStatus.GetOwner());
     Assert.Equal(group, fileStatus.GetGroup());
     if (symlink == null)
     {
         NUnit.Framework.Assert.IsFalse(fileStatus.IsSymlink());
     }
     else
     {
         Assert.True(fileStatus.IsSymlink());
         Assert.Equal(symlink, fileStatus.GetSymlink());
     }
     Assert.Equal(path, fileStatus.GetPath());
 }