drive

package
v0.0.0-...-df423d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Used to compare in case of OneNote files
	MaxOneNoteFileSize = 2 * 1024 * 1024 * 1024
)

Variables

This section is empty.

Functions

func CreateRestoreFolders

func CreateRestoreFolders(
	ctx context.Context,
	rh RestoreHandler,
	drivePath *path.DrivePath,
	restoreDir *path.Builder,
	folderPath path.Path,
	folderMetadata odmetadata.Metadata,
	caches *restoreCaches,
	restorePerms bool,
	errs *fault.Bus,
) (string, error)

CreateRestoreFolders creates the restore folder hierarchy in the specified drive and returns the folder ID of the last folder entry in the hierarchy. Permissions are only applied to the last folder in the hierarchy. Passing nil for the permissions results in just creating the folder(s). folderCache is mutated, as a side effect of populating the items.

func DeserializeMap

func DeserializeMap[T any](reader io.ReadCloser, alreadyFound map[string]T) error

DeserializeMap takes an reader and a map of already deserialized items and adds the newly deserialized items to alreadyFound. Items are only added to alreadyFound if none of the keys in the freshly deserialized map already exist in alreadyFound. reader is closed at the end of this function.

func DeserializeMetadata

func DeserializeMetadata(
	ctx context.Context,
	cols []data.RestoreCollection,
) (map[string]string, map[string]map[string]string, bool, error)

func DeserializeMetadataFiles

func DeserializeMetadataFiles(
	ctx context.Context,
	colls []data.RestoreCollection,
	counter *count.Bus,
) ([]store.MetadataFile, error)

func FetchAndReadMetadata

func FetchAndReadMetadata(
	ctx context.Context,
	fibn data.FetchItemByNamer,
	metaName string,
) (odmetadata.Metadata, error)

func NewExportCollection

func NewExportCollection(
	baseDir string,
	backingCollection []data.RestoreCollection,
	backupVersion int,
	stats *metrics.ExportStats,
) export.Collectioner

func NewFolderCache

func NewFolderCache() *folderCache

func NewGroupBackupHandler

func NewGroupBackupHandler(
	groupID, siteID string,
	ac api.Drives,
	scope selectors.GroupsScope,
) groupBackupHandler

func NewRestoreCaches

func NewRestoreCaches(
	backupDriveIDNames idname.Cacher,
) *restoreCaches

func NewSiteBackupHandler

func NewSiteBackupHandler(
	ac api.Drives,
	siteID string,
	scope selectors.SharePointScope,
	service path.ServiceType,
) siteBackupHandler

func NewSiteRestoreHandler

func NewSiteRestoreHandler(ac api.Client, service path.ServiceType) siteRestoreHandler

func NewUserDriveBackupHandler

func NewUserDriveBackupHandler(ac api.Drives, userID string, scope selectors.OneDriveScope) *userDriveBackupHandler

func NewUserDriveRestoreHandler

func NewUserDriveRestoreHandler(ac api.Client) *userDriveRestoreHandler

func RestoreCollection

func RestoreCollection(
	ctx context.Context,
	rh RestoreHandler,
	rcc inject.RestoreConsumerConfig,
	dc data.RestoreCollection,
	caches *restoreCaches,
	deets *details.Builder,
	fallbackDriveName string,
	errs *fault.Bus,
	ctr *count.Bus,
) (support.CollectionMetrics, error)

RestoreCollection handles restoration of an individual collection. returns: - the collection's item and byte count metrics - the updated metadata map that include metadata for folders in this collection - error, if any besides recoverable

func RestorePermissions

func RestorePermissions(
	ctx context.Context,
	rh RestoreHandler,
	driveID string,
	itemID string,
	itemPath path.Path,
	current odmetadata.Metadata,
	caches *restoreCaches,
	errs *fault.Bus,
)

RestorePermissions takes in the permissions of an item, computes what permissions need to added and removed based on the parent folder metas and uses that to add/remove the necessary permissions on onedrive items.

func UpdateLinkShares

func UpdateLinkShares(
	ctx context.Context,
	upils updateDeleteItemLinkSharer,
	driveID string,
	itemID string,
	lsAdded, lsRemoved []odmetadata.LinkShare,
	oldLinkShareIDToNewID syncd.MapTo[string],
	errs *fault.Bus,
) (bool, error)

func UpdatePermissions

func UpdatePermissions(
	ctx context.Context,
	udip updateDeleteItemPermissioner,
	driveID string,
	itemID string,
	permAdded, permRemoved []odmetadata.Permission,
	oldPermIDToNewID syncd.MapTo[string],
	errs *fault.Bus,
) error

UpdatePermissions takes in the set of permission to be added and removed from an item to bring it to the desired state.

Types

type BackupHandler

type BackupHandler interface {
	ItemInfoAugmenter
	api.Getter
	GetItemPermissioner
	GetItemer
	GetRootFolderer
	NewDrivePagerer
	EnumerateDriveItemsDeltaer

	// PathPrefix constructs the service and category specific path prefix for
	// the given values.
	PathPrefix(tenantID, driveID string) (path.Path, error)

	// MetadataPathPrefix returns the prefix path for metadata
	MetadataPathPrefix(tenantID string) (path.Path, error)

	// CanonicalPath constructs the service and category specific path for
	// the given values.
	CanonicalPath(folders *path.Builder, tenantID string) (path.Path, error)

	// ServiceCat returns the service and category used by this implementation.
	ServiceCat() (path.ServiceType, path.CategoryType)

	// FormatDisplayPath creates a human-readable string to represent the
	// provided path.
	FormatDisplayPath(driveName string, parentPath *path.Builder) string
	NewLocationIDer(driveID string, elems ...string) details.LocationIDer

	// scope wrapper funcs
	IsAllPass() bool
	IncludesDir(dir string) bool
}

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

Collection represents a set of OneDrive objects retrieved from M365

func NewCollection

func NewCollection(
	handler BackupHandler,
	resource idname.Provider,
	currPath path.Path,
	prevPath path.Path,
	driveID, driveName string,
	statusUpdater support.StatusUpdater,
	ctrlOpts control.Options,
	isPackageOrChildOfPackage bool,
	doNotMergeItems bool,
	urlCache getItemPropertyer,
	counter *count.Bus,
) (*Collection, error)

NewCollection creates a Collection

func (*Collection) Add

func (oc *Collection) Add(item *custom.DriveItem) bool

Adds an itemID to the collection. This will make it eligible to be populated. The return values denotes if the item was previously present or is new one.

func (Collection) ContainsItem

func (oc Collection) ContainsItem(item *custom.DriveItem) bool

ContainsItem returns true if the collection has the given item as one of its children.

func (Collection) CountAddedItems

func (oc Collection) CountAddedItems() int

AddedItems returns the number of non-deleted items in the collection.

func (Collection) DoNotMergeItems

func (oc Collection) DoNotMergeItems() bool

func (*Collection) FullPath

func (oc *Collection) FullPath() path.Path

func (*Collection) IsEmpty

func (oc *Collection) IsEmpty() bool

IsEmpty check if a collection does not contain any items

func (*Collection) Items

func (oc *Collection) Items(
	ctx context.Context,
	errs *fault.Bus,
) <-chan data.Item

Items() returns the channel containing M365 Exchange objects

func (Collection) LocationPath

func (oc Collection) LocationPath() *path.Builder

func (Collection) PreviousLocationPath

func (oc Collection) PreviousLocationPath() details.LocationIDer

func (Collection) PreviousPath

func (oc Collection) PreviousPath() path.Path

func (*Collection) Remove

func (oc *Collection) Remove(itemID string) bool

Remove removes a item from the collection

func (*Collection) SetFullPath

func (oc *Collection) SetFullPath(curPath path.Path)

func (Collection) State

func (oc Collection) State() data.CollectionState

type Collections

type Collections struct {

	// collectionMap allows lookup of the data.BackupCollection
	// for a OneDrive folder.
	// driveID -> itemID -> collection
	CollectionMap map[string]map[string]*Collection

	// Track stats from drive enumeration. Represents the items backed up.
	NumItems      int
	NumFiles      int
	NumContainers int
	// contains filtered or unexported fields
}

Collections is used to retrieve drive data for a resource owner, which can be either a user or a sharepoint site.

func NewCollections

func NewCollections(
	bh BackupHandler,
	tenantID string,
	protectedResource idname.Provider,
	statusUpdater support.StatusUpdater,
	ctrlOpts control.Options,
	counter *count.Bus,
) *Collections

func (*Collections) Get

func (c *Collections) Get(
	ctx context.Context,
	prevMetadata []data.RestoreCollection,
	globalExcludeItemIDs *prefixmatcher.StringSetMatchBuilder,
	errs *fault.Bus,
) ([]data.BackupCollection, bool, error)

Retrieves drive data as set of `data.Collections`.

func (*Collections) PopulateDriveCollections

func (c *Collections) PopulateDriveCollections(
	ctx context.Context,
	driveID, driveName string,
	oldPrevPaths map[string]string,
	excludedItemIDs map[string]struct{},
	topLevelPackages map[string]struct{},
	prevDeltaLink string,
	counter *count.Bus,
	errs *fault.Bus,
) (pagers.DeltaUpdate, map[string]string, error)

PopulateDriveCollections initializes and adds the provided drive items to Collections A new collection is created for every drive folder. Along with populating the collection items and updating the excluded item IDs, this func returns the current DeltaUpdate and PreviousPaths for metadata records.

type DeleteItemPermissioner

type DeleteItemPermissioner interface {
	DeleteItemPermission(
		ctx context.Context,
		driveID, itemID, permissionID string,
	) error
}

type DeleteItemer

type DeleteItemer interface {
	DeleteItem(
		ctx context.Context,
		driveID, itemID string,
	) error
}

type EnumerateDriveItemsDeltaer

type EnumerateDriveItemsDeltaer interface {
	EnumerateDriveItemsDelta(
		ctx context.Context,
		driveID, prevDeltaLink string,
		cc api.CallConfig,
	) pagers.NextPageResulter[models.DriveItemable]
}

type GetAllIDsAndNameser

type GetAllIDsAndNameser interface {
	GetAllIDsAndNames(ctx context.Context, errs *fault.Bus) (idname.Cacher, error)
}

type GetDrivePagerAndRootFolderer

type GetDrivePagerAndRootFolderer interface {
	GetRootFolderer
	NewDrivePagerer
}

type GetFolderByNamer

type GetFolderByNamer interface {
	GetFolderByName(
		ctx context.Context,
		driveID, parentFolderID, folderID string,
	) (models.DriveItemable, error)
}

type GetItemPermissioner

type GetItemPermissioner interface {
	GetItemPermission(
		ctx context.Context,
		driveID, itemID string,
	) (models.PermissionCollectionResponseable, error)
}

type GetItemer

type GetItemer interface {
	GetItem(
		ctx context.Context,
		driveID, itemID string,
	) (models.DriveItemable, error)
}

type GetItemsByCollisionKeyser

type GetItemsByCollisionKeyser interface {
	// GetItemsInContainerByCollisionKey looks up all items currently in
	// the container, and returns them in a map[collisionKey]itemID.
	// The collision key is uniquely defined by each category of data.
	// Collision key checks are used during restore to handle the on-
	// collision restore configurations that cause the item restore to get
	// skipped, replaced, or copied.
	GetItemsInContainerByCollisionKey(
		ctx context.Context,
		driveID, containerID string,
	) (map[string]api.DriveItemIDType, error)
}

type GetRootFolderer

type GetRootFolderer interface {
	// GetRootFolder gets the root folder for the drive.
	GetRootFolder(
		ctx context.Context,
		driveID string,
	) (models.DriveItemable, error)
}

type ItemInfoAugmenter

type ItemInfoAugmenter interface {
	// AugmentItemInfo will populate a details.<Service>Info struct
	// with properties from the drive item.  ItemSize is passed in
	// separately for restore processes because the local itemable
	// doesn't have its size value updated as a side effect of creation,
	// and kiota drops any SetSize update.
	AugmentItemInfo(
		dii details.ItemInfo,
		resource idname.Provider,
		item *custom.DriveItem,
		size int64,
		parentPath *path.Builder,
	) details.ItemInfo
}

type NewDrivePagerer

type NewDrivePagerer interface {
	NewDrivePager(resourceOwner string, fields []string) pagers.NonDeltaHandler[models.Driveable]
}

type NewItemContentUploader

type NewItemContentUploader interface {
	// NewItemContentUpload creates an upload session which is used as a writer
	// for large item content.
	NewItemContentUpload(
		ctx context.Context,
		driveID, itemID string,
	) (models.UploadSessionable, error)
}

type PostDriveAndGetRootFolderer

type PostDriveAndGetRootFolderer interface {
	PostDriver
	GetRootFolderer
}

type PostDriver

type PostDriver interface {
	PostDrive(
		ctx context.Context,
		protectedResourceID, driveName string,
	) (models.Driveable, error)
}

type PostItemInContainerer

type PostItemInContainerer interface {
	PostItemInContainer(
		ctx context.Context,
		driveID, parentFolderID string,
		newItem models.DriveItemable,
		onCollision control.CollisionPolicy,
	) (models.DriveItemable, error)
}

type ResourceIDNames

type ResourceIDNames struct {
	Users  idname.Cacher
	Groups idname.Cacher
}

type UpdateItemLinkSharer

type UpdateItemLinkSharer interface {
	PostItemLinkShareUpdate(
		ctx context.Context,
		driveID, itemID string,
		body *drives.ItemItemsItemCreateLinkPostRequestBody,
	) (models.Permissionable, error)
}

type UpdateItemPermissioner

type UpdateItemPermissioner interface {
	PostItemPermissionUpdate(
		ctx context.Context,
		driveID, itemID string,
		body *drives.ItemItemsItemInvitePostRequestBody,
	) (drives.ItemItemsItemInviteResponseable, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL