private async Task UnlinkDirectoriesRecursivelyAsync(GcsDirectoryEntry gcsDirectoryEntry, CancellationToken cancellationToken,
                                                             ConcurrentBag <GcsDirectoryEntry> foldersToDelete)
        {
            foldersToDelete.Add(gcsDirectoryEntry);

            try
            {
                var objects = await GetEntriesAsync(gcsDirectoryEntry, cancellationToken);

                foreach (var obj in objects)
                {
                    if (obj is GcsFileEntry file)
                    {
                        try
                        {
                            await _storageClient.DeleteObjectAsync(_bucketName, file.FullName,
                                                                   null, cancellationToken);
                        } catch { }
                    }
                    else if (obj is GcsDirectoryEntry dir)
                    {
                        await UnlinkDirectoriesRecursivelyAsync(dir, cancellationToken, foldersToDelete);
                    }
                }
            }
            catch { }
        }
        public GcsFileSystem(string bucketName)
        {
            FileSystemEntryComparer = StringComparer.OrdinalIgnoreCase;
            Root = new GcsDirectoryEntry(this)
            {
                Name = ""
            };

            _bucketName    = bucketName;
            _storageClient = StorageClient.Create();
        }
        public async Task <IUnixFileSystemEntry> GetEntryByNameAsync(IUnixDirectoryEntry directoryEntry, string name, CancellationToken cancellationToken)
        {
            IUnixFileSystemEntry result = null;
            var parentEntry             = (GcsDirectoryEntry)directoryEntry;
            var fullName = string.Join("/", new string[] { parentEntry.FullName.Trim('/'), name }).Trim('/');

            Google.Apis.Storage.v1.Data.Object obj = null;
            try
            {
                obj = await _storageClient.GetObjectAsync(_bucketName, fullName, null, cancellationToken);
            } catch { }
            if (obj == null)
            {
                var childEntry = new GcsDirectoryEntry(this)
                {
                    Name = $"{fullName}/"
                };
                var directoryExists = await DirectoryExistsAsync(childEntry);

                if (directoryExists)
                {
                    result = childEntry;
                }
            }
            else
            {
                if (obj.ContentType != "application/x-directory")
                {
                    DateTimeOffset?createdTime = null;
                    if (obj.TimeCreated is DateTime created)
                    {
                        createdTime = new DateTimeOffset(created);
                    }
                    DateTimeOffset?updatedTime = null;
                    if (obj.Updated is DateTime updated)
                    {
                        updatedTime = new DateTimeOffset(updated);
                    }
                    return(new GcsFileEntry(this)
                    {
                        Name = obj.Name,
                        Size = Convert.ToInt64(obj.Size),
                        CreatedTime = createdTime,
                        LastWriteTime = updatedTime
                    });
                }
            }

            return(result);
        }