Example #1
0
        public Dictionary <string, string> GetMetadata(string file, bool isSymlink, bool followSymlink)
        {
            var f    = NoSnapshot.NormalizePath(file);
            var dict = new Dictionary <string, string>();

            var n = UnixSupport.File.GetExtendedAttributes(f, isSymlink, followSymlink);

            if (n != null)
            {
                foreach (var x in n)
                {
                    dict["unix-ext:" + x.Key] = Convert.ToBase64String(x.Value);
                }
            }

            var fse = UnixSupport.File.GetUserGroupAndPermissions(f);

            dict["unix:uid-gid-perm"] = string.Format("{0}-{1}-{2}", fse.UID, fse.GID, fse.Permissions);
            if (fse.OwnerName != null)
            {
                dict["unix:owner-name"] = fse.OwnerName;
            }
            if (fse.GroupName != null)
            {
                dict["unix:group-name"] = fse.GroupName;
            }

            return(dict);
        }
Example #2
0
        public void SetMetadata(string file, Dictionary<string, string> data, bool restorePermissions)
        {
            if (data == null)
                return;

            var f = NoSnapshot.NormalizePath(file);

            foreach(var x in data.Where(x => x.Key.StartsWith("unix-ext:")).Select(x => new KeyValuePair<string, byte[]>(x.Key.Substring("unix-ext:".Length), Convert.FromBase64String(x.Value))))
                UnixSupport.File.SetExtendedAttribute(f, x.Key, x.Value);

            if (restorePermissions && data.ContainsKey("unix:uid-gid-perm"))
            {
                var parts = data["unix:uid-gid-perm"].Split(new char[] { '-' });
                if (parts.Length == 3)
                {
                    long uid;
                    long gid;
                    long perm;

                    if (long.TryParse(parts[0], out uid) && long.TryParse(parts[1], out gid) && long.TryParse(parts[2], out perm))
                    {
                        if (data.ContainsKey("unix:owner-name"))
                            try { uid = UnixSupport.File.GetUserID(data["unix:owner-name"]); }
                            catch { }

                        if (data.ContainsKey("unix:group-name"))
                            try { gid = UnixSupport.File.GetGroupID(data["unix:group-name"]); }
                            catch { }

                        UnixSupport.File.SetUserGroupAndPermissions(f, uid, gid, perm);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Gets a unique hardlink target ID
        /// </summary>
        /// <returns>The hardlink ID</returns>
        /// <param name="file">The file or folder to examine</param>
        public string HardlinkTargetID(string path)
        {
            var local = ConvertToSnapshotPath(FindSnapShotByLocalPath(path), path);

            local = NoSnapshot.NormalizePath(local);

            if (UnixSupport.File.GetHardlinkCount(local) <= 1)
            {
                return(null);
            }

            return(UnixSupport.File.GetInodeTargetID(local));
        }
Example #4
0
        /// <summary>
        /// Gets a value indicating if the path points to a block device
        /// </summary>
        /// <returns><c>true</c> if this instance is a block device; otherwise, <c>false</c>.</returns>
        /// <param name="file">The file or folder to examine</param>
        public bool IsBlockDevice(string file)
        {
            var n = UnixSupport.File.GetFileType(NoSnapshot.NormalizePath(file));

            switch (n)
            {
            case UnixSupport.File.FileType.Directory:
            case UnixSupport.File.FileType.Symlink:
            case UnixSupport.File.FileType.File:
                return(false);

            default:
                return(true);
            }
        }
Example #5
0
        /// <summary>
        /// Returns the symlink target if the entry is a symlink, and null otherwise
        /// </summary>
        /// <param name="file">The file or folder to examine</param>
        /// <returns>The symlink target</returns>
        public string GetSymlinkTarget(string file)
        {
            var local = ConvertToSnapshotPath(FindSnapShotByLocalPath(file), file);

            return(UnixSupport.File.GetSymlinkTarget(NoSnapshot.NormalizePath(local)));
        }
Example #6
0
 public FileAttributes GetFileAttributes(string path)
 {
     return(File.GetAttributes(NoSnapshot.NormalizePath(path)));
 }
Example #7
0
 public bool DirectoryExists(string path)
 {
     return(Directory.Exists(NoSnapshot.NormalizePath(path)));
 }
Example #8
0
 public void DirectoryCreate(string path)
 {
     Directory.CreateDirectory(NoSnapshot.NormalizePath(path));
 }
Example #9
0
 public void DirectoryDelete(string path)
 {
     Directory.Delete(NoSnapshot.NormalizePath(path));
 }
Example #10
0
 public void DirectoryDelete(string path, bool recursive)
 {
     Directory.Delete(NoSnapshot.NormalizePath(path), recursive);
 }
Example #11
0
 public DateTime DirectoryGetCreationTimeUtc(string path)
 {
     return(Directory.GetCreationTimeUtc(NoSnapshot.NormalizePath(path)));
 }
Example #12
0
 public void DirectorySetCreationTimeUtc(string path, DateTime time)
 {
     Directory.SetCreationTimeUtc(NoSnapshot.NormalizePath(path), time);
 }
Example #13
0
 public string PathGetDirectoryName(string path)
 {
     return(Path.GetDirectoryName(NoSnapshot.NormalizePath(path)));
 }
Example #14
0
 public string GetSymlinkTarget(string path)
 {
     return(UnixSupport.File.GetSymlinkTarget(NoSnapshot.NormalizePath(path)));
 }
Example #15
0
 public DateTime DirectoryGetLastWriteTimeUtc(string path)
 {
     return Directory.GetLastWriteTimeUtc(NoSnapshot.NormalizePath(path));
 }