Exemple #1
0
        /// <summary>
        /// Starts all of the necessary operations to rename the directory <paramref name="oldLeafName"/> to
        /// the <paramref name="newLeafName"/> name. This includes renaming the directory and all subdirectories and files
        /// under the directory being renamed.
        /// </summary>
        /// <param name="bucket">The bucket where the directory to rename resides.</param>
        /// <param name="parentName">The parent directory of the directory being renamed.</param>
        /// <param name="oldLeafName">The old (current) name of the directory.</param>
        /// <param name="newLeafName">The new name for the directory.</param>
        /// <param name="cancellationToken">The cancellation token for the operaitons.</param>
        /// <returns></returns>
        public async Task <OperationsQueue> StartDirectoryRenameOperationsAsync(
            string bucket,
            string parentName,
            string oldLeafName,
            string newLeafName,
            CancellationToken cancellationToken)
        {
            var oldNamePrefix = GcsPathUtils.Combine(parentName, oldLeafName) + "/";
            var newNamePrefix = GcsPathUtils.Combine(parentName, newLeafName) + "/";

            var filesToMove = await GetGcsFilesFromPrefixAsync(bucket, oldNamePrefix);

            var moveOperations = new List <GcsMoveFileOperation>();

            foreach (var file in filesToMove)
            {
                var movedName = newNamePrefix + file.Name.Substring(oldNamePrefix.Length);
                var movedItem = new GcsItemRef(bucket, movedName);
                moveOperations.Add(new GcsMoveFileOperation(file, movedItem));
            }

            var operationsQueue = new OperationsQueue(cancellationToken);

            operationsQueue.EnqueueOperations(moveOperations, _dataSource.StartMoveOperation);
            operationsQueue.StartOperations();
            return(operationsQueue);
        }
        public GcsMoveFileOperation(GcsItemRef fromItem, GcsItemRef toItem)
        {
            if (fromItem.Bucket != toItem.Bucket)
            {
                throw new InvalidOperationException("Can only move items within the same bucket.");
            }

            GcsItem = fromItem;
            ToItem  = toItem;
        }