Esempio n. 1
0
        /// <inheritdoc />
        public async Task <IUnixFileSystemEntry?> GetEntryByNameAsync(
            IUnixDirectoryEntry directoryEntry,
            string name,
            CancellationToken cancellationToken)
        {
            var key = S3Path.Combine(((S3DirectoryEntry)directoryEntry).Key, name);

            var entry = await GetObjectAsync(key, cancellationToken);

            if (entry != null)
            {
                return(entry);
            }

            // not a file search for directory
            key += '/';

            var objects = await ListObjectsAsync(key, true, cancellationToken);

            if (objects.Count > 0)
            {
                return(new S3DirectoryEntry(key));
            }

            return(null);
        }
        /// <inheritdoc />
        public Task <IUnixFileSystem> Create(IAccountInformation accountInformation)
        {
            var directories = _accountDirectoryQuery.GetDirectories(accountInformation);

            return(Task.FromResult <IUnixFileSystem>(
                       new S3FileSystem(_options, S3Path.Combine(_options.RootPath, directories.RootPath))));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public async Task <IBackgroundTransfer?> CreateAsync(
            IUnixDirectoryEntry targetDirectory,
            string fileName,
            Stream data,
            CancellationToken cancellationToken)
        {
            var key = S3Path.Combine(((S3DirectoryEntry)targetDirectory).Key, fileName);

            await UploadFile(data, key, cancellationToken);

            return(default);
Esempio n. 4
0
        /// <inheritdoc />
        public async Task <IUnixDirectoryEntry> CreateDirectoryAsync(
            IUnixDirectoryEntry targetDirectory,
            string directoryName,
            CancellationToken cancellationToken)
        {
            var key = S3Path.Combine(((S3DirectoryEntry)targetDirectory).Key, directoryName + "/");

            await _client.PutObjectAsync(
                new PutObjectRequest
            {
                BucketName = _options.BucketName,
                Key        = key,
            },
                cancellationToken);

            return(new S3DirectoryEntry(key));
        }
Esempio n. 5
0
        /// <inheritdoc />
        public async Task <IUnixFileSystemEntry?> GetEntryByNameAsync(
            IUnixDirectoryEntry directoryEntry,
            string name,
            CancellationToken cancellationToken)
        {
            var prefix = S3Path.Combine(((S3DirectoryEntry)directoryEntry).Key, name);

            var objects = await ListObjectsAsync(prefix, cancellationToken);

            if (objects.Count == 1 && objects.Single() is IUnixFileEntry entry)
            {
                return(entry);
            }

            if (objects.Count > 0)
            {
                return(new S3DirectoryEntry(prefix));
            }

            return(null);
        }
Esempio n. 6
0
        /// <inheritdoc />
        public async Task <IUnixFileSystemEntry> MoveAsync(
            IUnixDirectoryEntry parent,
            IUnixFileSystemEntry source,
            IUnixDirectoryEntry target,
            string fileName,
            CancellationToken cancellationToken)
        {
            var sourceKey = ((S3FileSystemEntry)source).Key;
            var key       = S3Path.Combine(((S3DirectoryEntry)target).Key, fileName);

            if (source is S3FileEntry file)
            {
                await MoveFile(sourceKey, key, cancellationToken);

                return(new S3FileEntry(key, file.Size)
                {
                    LastWriteTime = file.LastWriteTime ?? DateTimeOffset.UtcNow,
                });
            }

            if (source is S3DirectoryEntry)
            {
                key += '/';
                ListObjectsResponse response;
                do
                {
                    response = await _client.ListObjectsAsync(_options.BucketName, sourceKey, cancellationToken);

                    foreach (var s3Object in response.S3Objects)
                    {
                        await MoveFile(s3Object.Key, key + s3Object.Key.Substring(sourceKey.Length), cancellationToken);
                    }
                }while (response.IsTruncated);

                return(new S3DirectoryEntry(key));
            }

            throw new InvalidOperationException();
        }