< Summary

Class:Azure.Storage.Files.DataLake.Models.PathPermissions
Assembly:Azure.Storage.Files.DataLake
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Models\PathPermissions.cs
Covered lines:64
Uncovered lines:3
Coverable lines:67
Total lines:213
Line coverage:95.5% (64 of 67)
Covered branches:23
Total branches:26
Branch coverage:88.4% (23 of 26)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Owner()-100%100%
get_Group()-100%100%
get_Other()-100%100%
get_StickyBit()-100%100%
get_ExtendedAcls()-100%100%
.ctor()-100%100%
.ctor(...)-100%100%
ParseOctalPermissions(...)-92.86%87.5%
ParseSymbolicPermissions(...)-88.24%83.33%
ToOctalPermissions()-100%100%
ToSymbolicPermissions()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Models\PathPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Globalization;
 6using System.Text;
 7
 8namespace Azure.Storage.Files.DataLake.Models
 9{
 10    /// <summary>
 11    /// Represents POSIX-style permissions on a given resource. Each resource specifies permissions for the owner, the o
 12    /// group, and everyone else. Permissions for users or groups not included here can be set using an Access Control L
 13    /// Manipulating resource permissions is only supported when ADLS interop is enabled.
 14    /// </summary>
 15    public class PathPermissions
 16    {
 17        /// <summary>
 18        /// The <see cref="RolePermissions"/> for the owner of the resource.
 19        /// </summary>
 49220        public RolePermissions Owner { get; set; }
 21
 22        /// <summary>
 23        /// The <see cref="RolePermissions"/> for the owning group of the resource.
 24        /// </summary>
 49225        public RolePermissions Group { get; set; }
 26
 27        /// <summary>
 28        /// The <see cref="RolePermissions"/> for the other users.
 29        /// </summary>
 49230        public RolePermissions Other { get; set; }
 31
 32        /// <summary>
 33        /// If the sticky bit has been set. The sticky bit may be set on directories, the files in that
 34        /// directory may only be renamed or deleted by the file's owner, the directory's owner, or the root user.
 35        /// </summary>
 49236        public bool StickyBit { get; set; }
 37
 38        /// <summary>
 39        /// Whether or not there is more permissions information in the ACLs. The permissions string only returns
 40        /// information on the owner, owning group, and other, but the ACLs may contain more permissions for specific us
 41        /// or groups.
 42        /// </summary>
 48443        public bool ExtendedAcls { get; set; }
 44
 45        /// <summary>
 46        /// Internal empty constructor.
 47        /// </summary>
 53248        public PathPermissions() { }
 49
 50        /// <summary>
 51        /// Public constructor.
 52        /// </summary>
 53        /// <param name="owner">The path owner's permissions.</param>
 54        /// <param name="group">The path group's permissions.</param>
 55        /// <param name="other">Permissions for other users.</param>
 56        /// <param name="stickyBit">If sticky bit is enabled</param>
 57        /// <param name="extendedInfoInAcl">If there is extended info in the ACL</param>
 2458        public PathPermissions(
 2459            RolePermissions owner,
 2460            RolePermissions group,
 2461            RolePermissions other,
 2462            bool stickyBit = false,
 2463            bool extendedInfoInAcl = false)
 64        {
 2465            Owner = owner;
 2466            Group = group;
 2467            Other = other;
 2468            StickyBit = stickyBit;
 2469            ExtendedAcls = extendedInfoInAcl;
 2470        }
 71
 72        /// <summary>
 73        /// Parses a string in octal format to PathPermissions.
 74        /// </summary>
 75        /// <param name="s">Octal string to parse.</param>
 76        /// <returns><see cref="PathPermissions"/>.</returns>
 77        public static PathPermissions ParseOctalPermissions(string s)
 78        {
 879            if (s == null)
 80            {
 081                return null;
 82            }
 83
 884            if (s.Length != 4)
 85            {
 286                throw DataLakeErrors.PathPermissionsOctalInvalidLength(s);
 87            }
 88
 689            var pathPermissions = new PathPermissions();
 90
 691            if (s[0] == '0')
 92            {
 293                pathPermissions.StickyBit = false;
 94            }
 495            else if (s[0] == '1')
 96            {
 297                pathPermissions.StickyBit = true;
 98            }
 99            else
 100            {
 2101                throw DataLakeErrors.PathPermissionsOctalInvalidFirstDigit(s);
 102            }
 103
 4104            pathPermissions.Owner = PathAccessControlExtensions.ParseOctalRolePermissions(s[1]);
 4105            pathPermissions.Group = PathAccessControlExtensions.ParseOctalRolePermissions(s[2]);
 4106            pathPermissions.Other = PathAccessControlExtensions.ParseOctalRolePermissions(s[3]);
 107
 4108            return pathPermissions;
 109        }
 110
 111        /// <summary>
 112        /// Parses a symbolic string to PathPermissions.
 113        /// </summary>
 114        /// <param name="s">String to parse.</param>
 115        /// <returns><see cref="PathPermissions"/>.</returns>
 116        public static PathPermissions ParseSymbolicPermissions(string s)
 117        {
 262118            if (s == null)
 119            {
 0120                return null;
 121            }
 122
 262123            if (s.Length != 9 && s.Length != 10)
 124            {
 2125                throw DataLakeErrors.PathPermissionsSymbolicInvalidLength(s);
 126            }
 127
 260128            var pathPermissions = new PathPermissions();
 129
 130            // Set sticky bit
 260131            if (char.ToLower(s[8], CultureInfo.InvariantCulture) == 't')
 132            {
 4133                pathPermissions.StickyBit = true;
 134            }
 135            else
 136            {
 256137                pathPermissions.StickyBit = false;
 138            }
 139
 140            // Set extended info in ACL
 260141            if (s.Length == 10)
 142            {
 4143                if (s[9] == '+')
 144                {
 4145                    pathPermissions.ExtendedAcls = true;
 146                }
 147                else
 148                {
 0149                    throw Errors.InvalidFormat(nameof(s));
 150                }
 151            }
 152            else
 153            {
 256154                pathPermissions.ExtendedAcls = false;
 155            }
 156
 260157            pathPermissions.Owner = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(0, 3), allowSti
 260158            pathPermissions.Group = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(3, 3), allowSti
 260159            pathPermissions.Other = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(6, 3), allowSti
 160
 260161            return pathPermissions;
 162        }
 163
 164        /// <summary>
 165        /// Returns the octal representation of this PathPermissions as a string.
 166        /// </summary>
 167        /// <returns>string</returns>
 168        public string ToOctalPermissions()
 169        {
 4170            var sb = new StringBuilder();
 171
 4172            if (StickyBit)
 173            {
 2174                sb.Append(1);
 175            }
 176            else
 177            {
 2178                sb.Append(0);
 179            }
 180
 4181            sb.Append(Owner.ToOctalRolePermissions());
 4182            sb.Append(Group.ToOctalRolePermissions());
 4183            sb.Append(Other.ToOctalRolePermissions());
 184
 4185            return sb.ToString();
 186        }
 187
 188        /// <summary>
 189        /// Returns the symbolic represenation of this PathPermissions as a string.
 190        /// </summary>
 191        /// <returns>string.</returns>
 192        public string ToSymbolicPermissions()
 193        {
 112194            var sb = new StringBuilder();
 112195            sb.Append(Owner.ToSymbolicRolePermissions());
 112196            sb.Append(Group.ToSymbolicRolePermissions());
 112197            sb.Append(Other.ToSymbolicRolePermissions());
 198
 112199            if (StickyBit)
 200            {
 4201                sb.Remove(8, 1);
 4202                sb.Append("t");
 203            }
 204
 112205            if (ExtendedAcls)
 206            {
 4207                sb.Append("+");
 208            }
 209
 112210            return sb.ToString();
 211        }
 212    }
 213}