/// <summary> /// Parses a string in octal format to PathPermissions. /// </summary> /// <param name="s">Octal string to parse.</param> /// <returns><see cref="PathPermissions"/>.</returns> public static PathPermissions ParseOctalPermissions(string s) { if (s == null) { return(null); } if (s.Length != 4) { throw DataLakeErrors.PathPermissionsOctalInvalidLength(s); } var pathPermissions = new PathPermissions(); if (s[0] == '0') { pathPermissions.StickyBit = false; } else if (s[0] == '1') { pathPermissions.StickyBit = true; } else { throw DataLakeErrors.PathPermissionsOctalInvalidFirstDigit(s); } pathPermissions.Owner = PathAccessControlExtensions.ParseOctalRolePermissions(s[1]); pathPermissions.Group = PathAccessControlExtensions.ParseOctalRolePermissions(s[2]); pathPermissions.Other = PathAccessControlExtensions.ParseOctalRolePermissions(s[3]); return(pathPermissions); }
/// <summary> /// Creates a new <see cref="PathAccessControl"/> instance for mocking. /// </summary> public static PathAccessControl PathAccessControl( string owner, string group, PathPermissions permissions, IList <PathAccessControlItem> acl) => new PathAccessControl() { Owner = owner, Group = group, Permissions = permissions, AccessControlList = acl };
/// <summary> /// Parses a symbolic string to PathPermissions. /// </summary> /// <param name="s">String to parse.</param> /// <returns><see cref="PathPermissions"/>.</returns> public static PathPermissions ParseSymbolicPermissions(string s) { if (s == null) { return(null); } if (s.Length != 9 && s.Length != 10) { throw DataLakeErrors.PathPermissionsSymbolicInvalidLength(s); } var pathPermissions = new PathPermissions(); // Set sticky bit if (char.ToLower(s[8], CultureInfo.InvariantCulture) == 't') { pathPermissions.StickyBit = true; } else { pathPermissions.StickyBit = false; } // Set extended info in ACL if (s.Length == 10) { if (s[9] == '+') { pathPermissions.ExtendedAcls = true; } else { throw Errors.InvalidFormat(nameof(s)); } } else { pathPermissions.ExtendedAcls = false; } pathPermissions.Owner = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(0, 3), allowStickyBit: false); pathPermissions.Group = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(3, 3), allowStickyBit: false); pathPermissions.Other = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(6, 3), allowStickyBit: true); return(pathPermissions); }