Files

50 lines
2.4 KiB
C#
Raw Permalink Normal View History

// Copyright (c) 2026 Duplicati Inc. All rights reserved.
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
2026-02-15 22:03:57 +01:00
using Google.Apis.Drive.v3;
using System.Runtime.CompilerServices;
using File = Google.Apis.Drive.v3.Data.File;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
2026-02-15 22:03:57 +01:00
internal class DriveFileSourceEntry(string parentPath, File file, DriveService driveService)
2026-02-16 13:03:38 +01:00
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, file.Id)), file.CreatedTimeDateTimeOffset.HasValue ? file.CreatedTimeDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch, file.ModifiedTimeDateTimeOffset.HasValue ? file.ModifiedTimeDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch)
{
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new DriveFileMetadataSourceEntry(this.Path, file);
if (cancellationToken.IsCancellationRequested) yield break;
2026-02-15 22:03:57 +01:00
yield return new DriveFilePermissionsSourceEntry(this.Path, file, driveService);
if (cancellationToken.IsCancellationRequested) yield break;
2026-02-15 22:03:57 +01:00
yield return new DriveFileContentSourceEntry(this.Path, file, driveService);
if (cancellationToken.IsCancellationRequested) yield break;
2026-02-15 22:03:57 +01:00
yield return new DriveFileCommentsSourceEntry(this.Path, file, driveService);
2026-02-16 16:40:30 +01:00
// Skip revisions for Google Workspace files (Docs, Sheets, Slides, Sites, Shortcuts) as they cannot be exported
if (!GoogleMimeTypes.IsGoogleSite(file.MimeType) && !GoogleMimeTypes.IsShortcut(file.MimeType) && !GoogleMimeTypes.IsGoogleDoc(file.MimeType))
{
if (cancellationToken.IsCancellationRequested) yield break;
2026-02-15 22:03:57 +01:00
yield return new DriveFileRevisionsSourceEntry(this.Path, file, driveService);
}
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "gsuite:v", "1" },
{ "gsuite:Type", SourceItemType.DriveFile.ToString() },
{ "gsuite:Name", file.Name },
{ "gsuite:Id", file.Id },
{ "gsuite:MimeType", file.MimeType }
}
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value));
}
}