CmisSync.Lib.Storage.FileSystem.ExtendedAttributeReaderUnix.GetExtendedAttribute C# (CSharp) Method

GetExtendedAttribute() public method

Gets the extended attribute.
public GetExtendedAttribute ( string path, string key ) : string
path string Path to the file or folder.
key string Key of the extended attribute.
return string
        public string GetExtendedAttribute(string path, string key) {
            path = Path.GetFullPath(path);
            if (!File.Exists(path) && !Directory.Exists(path)) {
                throw new FileNotFoundException(string.Format("{0}: on path \"{1}\"", "No such file or directory", path), path);
            }

#if __MonoCS__
            byte[] value;
            long ret = Syscall.getxattr(path, prefix + key, out value);
#if __COCOA__
            if (ret != 0)
            {
                // On MacOS 93 means no value is found
                if (ret == 93) {
                    return null;
                }
            }
#else
            if (ret == -1) {
                Errno error = Syscall.GetLastError();
                if(error.ToString().Equals("ENODATA")) {
                    return null;
                } else {
                    throw new ExtendedAttributeException(string.Format("{0}: on path \"{1}\"", Syscall.GetLastError().ToString(), path));
                }
            }
#endif
            if (value == null) {
                return null;
            } else {
                return Encoding.UTF8.GetString(value);
            }
#else
            throw new WrongPlatformException();
#endif
        }

Usage Example

 public void GetNullAttributeFromNewFile()
 {
     using (File.Create(path));
     string key = "test";
     var reader = new ExtendedAttributeReaderUnix();
     Assert.That(reader.GetExtendedAttribute(path, key), Is.Null);
 }
All Usage Examples Of CmisSync.Lib.Storage.FileSystem.ExtendedAttributeReaderUnix::GetExtendedAttribute