public async Task UpdateLocation()

in src/Microsoft.IIS.Administration.Files/LocationsHelper.cs [141:219]


        public async Task<ILocation> UpdateLocation(dynamic model, ILocation location)
        {
            if (model == null) {
                throw new ApiArgumentException("model");
            }

            string alias = DynamicHelper.Value(model.alias);
            string path = DynamicHelper.Value(model.path);

            if (!string.IsNullOrEmpty(alias) && !PathUtil.IsValidFileName(alias)) {
                throw new ApiArgumentException("alias");
            }

            if (!string.IsNullOrEmpty(path) && !PathUtil.IsFullPath(System.Environment.ExpandEnvironmentVariables(path))) {
                throw new ApiArgumentException("path");
            }

            IEnumerable<string> claims = null;
            if (model.claims != null) {

                if (!(model.claims is JArray)) {
                    throw new ApiArgumentException("claims", ApiArgumentException.EXPECTED_ARRAY);
                }

                claims = (model.claims as JArray).ToObject<IEnumerable<string>>();

                foreach (string claim in claims) {
                    if (!claim.Equals("read", StringComparison.OrdinalIgnoreCase)
                         && !claim.Equals("write", StringComparison.OrdinalIgnoreCase)) {
                        throw new ApiArgumentException("claim");
                    }
                }
            }

            if (!string.IsNullOrEmpty(alias) && !alias.Equals(location.Alias, StringComparison.OrdinalIgnoreCase) && 
                    _options.Locations.Any(loc => loc.Alias.Equals(alias, StringComparison.OrdinalIgnoreCase))) {

                throw new AlreadyExistsException("alias");
            }

            if (path != null && !path.Equals(location.GetRawPath(), StringComparison.OrdinalIgnoreCase) &&
                    _options.Locations.Any(loc => loc.GetRawPath().Equals(path, StringComparison.OrdinalIgnoreCase))) {

                throw new AlreadyExistsException("path");
            }

            //
            // Claims are read only so we must create a new location
            ILocation newLocation = new Location() {
                Alias = alias ?? location.Alias,
                Path = path ?? location.GetRawPath(),
                Claims = claims ?? location.Claims
            };

            //
            // If path updated create directory
            if (path != null) {
                CreateIfNecessary(newLocation);
            }

            List<ILocation> locations = new List<ILocation>();

            foreach (var loc in _options.Locations) {
                if (loc == location) {
                    //
                    // Replace the old location with the new location
                    locations.Add(newLocation);
                }
                else {
                    locations.Add(loc);
                }
            }

            await WriteLocations(locations);

            //
            // Retreive the new location from the refreshed file options
            return _options.Locations.FirstOrDefault(loc => ((IRawPath)loc).RawPath.Equals(newLocation.Path));
        }