diff --git a/src/internal/data/implementations.go b/src/internal/data/implementations.go index 15b7dffb3..d75bd93b6 100644 --- a/src/internal/data/implementations.go +++ b/src/internal/data/implementations.go @@ -13,10 +13,10 @@ var ErrNotFound = clues.New("not found") type CollectionState int const ( - NewState = CollectionState(iota) - NotMovedState - MovedState - DeletedState + NewState CollectionState = 0 + NotMovedState CollectionState = 1 + MovedState CollectionState = 2 + DeletedState CollectionState = 3 ) type FetchRestoreCollection struct { diff --git a/src/internal/m365/collection/drive/collections.go b/src/internal/m365/collection/drive/collections.go index a2161f779..6964774b8 100644 --- a/src/internal/m365/collection/drive/collections.go +++ b/src/internal/m365/collection/drive/collections.go @@ -31,13 +31,13 @@ type collectionScope int const ( // CollectionScopeUnknown is used when we don't know and don't need // to know the kind, like in the case of deletes - CollectionScopeUnknown collectionScope = iota + CollectionScopeUnknown collectionScope = 0 // CollectionScopeFolder is used for regular folder collections - CollectionScopeFolder + CollectionScopeFolder collectionScope = 1 // CollectionScopePackage is used to represent OneNote items - CollectionScopePackage + CollectionScopePackage collectionScope = 2 ) const restrictedDirectory = "Site Pages" diff --git a/src/internal/m365/collection/drive/metadata/permissions.go b/src/internal/m365/collection/drive/metadata/permissions.go index ec0cc22f0..53f549110 100644 --- a/src/internal/m365/collection/drive/metadata/permissions.go +++ b/src/internal/m365/collection/drive/metadata/permissions.go @@ -14,8 +14,8 @@ import ( type SharingMode int const ( - SharingModeCustom = SharingMode(iota) - SharingModeInherited + SharingModeCustom SharingMode = 0 + SharingModeInherited SharingMode = 1 ) type GV2Type string diff --git a/src/internal/m365/collection/site/backup.go b/src/internal/m365/collection/site/backup.go index 14f1333be..8357d9512 100644 --- a/src/internal/m365/collection/site/backup.go +++ b/src/internal/m365/collection/site/backup.go @@ -59,6 +59,7 @@ func CollectPages( bpc inject.BackupProducerConfig, creds account.M365Config, ac api.Client, + scope selectors.SharePointScope, su support.StatusUpdater, errs *fault.Bus, ) ([]data.BackupCollection, error) { @@ -105,7 +106,7 @@ func CollectPages( collection := NewCollection( dir, ac, - Pages, + scope, su, bpc.Options) collection.SetBetaService(betaService) @@ -122,6 +123,7 @@ func CollectLists( bpc inject.BackupProducerConfig, ac api.Client, tenantID string, + scope selectors.SharePointScope, su support.StatusUpdater, errs *fault.Bus, ) ([]data.BackupCollection, error) { @@ -156,7 +158,7 @@ func CollectLists( collection := NewCollection( dir, ac, - List, + scope, su, bpc.Options) collection.AddJob(tuple.ID) diff --git a/src/internal/m365/collection/site/backup_test.go b/src/internal/m365/collection/site/backup_test.go index de0d91c50..46dff1a97 100644 --- a/src/internal/m365/collection/site/backup_test.go +++ b/src/internal/m365/collection/site/backup_test.go @@ -16,6 +16,7 @@ import ( "github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/fault" + "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -61,11 +62,14 @@ func (suite *SharePointPagesSuite) TestCollectPages() { ProtectedResource: mock.NewProvider(siteID, siteID), } + sel := selectors.NewSharePointBackup([]string{siteID}) + col, err := CollectPages( ctx, bpc, creds, ac, + sel.Lists(selectors.Any())[0], (&MockGraphService{}).UpdateStatus, fault.New(true)) assert.NoError(t, err, clues.ToCore(err)) diff --git a/src/internal/m365/collection/site/collection.go b/src/internal/m365/collection/site/collection.go index a293e40a0..a6196a4ed 100644 --- a/src/internal/m365/collection/site/collection.go +++ b/src/internal/m365/collection/site/collection.go @@ -21,19 +21,23 @@ import ( "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/path" + "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/services/m365/api" ) type DataCategory int +// channel sizes +const ( + collectionChannelBufferSize = 50 + fetchChannelSize = 5 +) + //go:generate stringer -type=DataCategory const ( - collectionChannelBufferSize = 50 - fetchChannelSize = 5 - Unknown DataCategory = iota - List - Drive - Pages + Unknown DataCategory = 0 + List DataCategory = 1 + Pages DataCategory = 2 ) var ( @@ -53,7 +57,7 @@ type Collection struct { // jobs contain the SharePoint.Site.ListIDs for the associated list(s). jobs []string // M365 IDs of the items of this collection - category DataCategory + category path.CategoryType client api.Sites ctrl control.Options betaService *betaAPI.BetaService @@ -64,7 +68,7 @@ type Collection struct { func NewCollection( folderPath path.Path, ac api.Client, - category DataCategory, + scope selectors.SharePointScope, statusUpdater support.StatusUpdater, ctrlOpts control.Options, ) *Collection { @@ -74,7 +78,7 @@ func NewCollection( data: make(chan data.Item, collectionChannelBufferSize), client: ac.Sites(), statusUpdater: statusUpdater, - category: category, + category: scope.Category().PathType(), ctrl: ctrlOpts, } @@ -198,9 +202,9 @@ func (sc *Collection) runPopulate( // Switch retrieval function based on category switch sc.category { - case List: + case path.ListsCategory: metrics, err = sc.retrieveLists(ctx, writer, colProgress, errs) - case Pages: + case path.PagesCategory: metrics, err = sc.retrievePages(ctx, sc.client, writer, colProgress, errs) } diff --git a/src/internal/m365/collection/site/collection_test.go b/src/internal/m365/collection/site/collection_test.go index f3f19c7e4..390d5cd14 100644 --- a/src/internal/m365/collection/site/collection_test.go +++ b/src/internal/m365/collection/site/collection_test.go @@ -23,6 +23,7 @@ import ( "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" + "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -82,16 +83,18 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() { dirRoot = "directory" ) + sel := selectors.NewSharePointBackup([]string{"site"}) + tables := []struct { name, itemName string - category DataCategory + scope selectors.SharePointScope getDir func(t *testing.T) path.Path getItem func(t *testing.T, itemName string) *Item }{ { name: "List", itemName: "MockListing", - category: List, + scope: sel.Lists(selectors.Any())[0], getDir: func(t *testing.T) path.Path { dir, err := path.Build( tenant, @@ -127,7 +130,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() { { name: "Pages", itemName: "MockPages", - category: Pages, + scope: sel.Pages(selectors.Any())[0], getDir: func(t *testing.T) path.Path { dir, err := path.Build( tenant, @@ -166,7 +169,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() { col := NewCollection( test.getDir(t), suite.ac, - test.category, + test.scope, nil, control.DefaultOptions()) col.data <- test.getItem(t, test.itemName) diff --git a/src/internal/m365/collection/site/datacategory_string.go b/src/internal/m365/collection/site/datacategory_string.go deleted file mode 100644 index eac0006cc..000000000 --- a/src/internal/m365/collection/site/datacategory_string.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by "stringer -type=DataCategory"; DO NOT EDIT. - -package site - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[Unknown-2] - _ = x[List-3] - _ = x[Drive-4] - _ = x[Pages-5] -} - -const _DataCategory_name = "UnknownListDrivePages" - -var _DataCategory_index = [...]uint8{0, 7, 11, 16, 21} - -func (i DataCategory) String() string { - i -= 2 - if i < 0 || i >= DataCategory(len(_DataCategory_index)-1) { - return "DataCategory(" + strconv.FormatInt(int64(i+2), 10) + ")" - } - return _DataCategory_name[_DataCategory_index[i]:_DataCategory_index[i+1]] -} diff --git a/src/internal/m365/service/sharepoint/backup.go b/src/internal/m365/service/sharepoint/backup.go index 479d4ac24..c4604e609 100644 --- a/src/internal/m365/service/sharepoint/backup.go +++ b/src/internal/m365/service/sharepoint/backup.go @@ -63,6 +63,7 @@ func ProduceBackupCollections( bpc, ac, creds.AzureTenantID, + scope, su, errs) if err != nil { @@ -95,6 +96,7 @@ func ProduceBackupCollections( bpc, creds, ac, + scope, su, errs) if err != nil { diff --git a/src/internal/m365/support/status.go b/src/internal/m365/support/status.go index b1a7d2449..5e85857eb 100644 --- a/src/internal/m365/support/status.go +++ b/src/internal/m365/support/status.go @@ -37,10 +37,10 @@ type Operation int //go:generate stringer -type=Operation const ( - OpUnknown Operation = iota - Backup - Restore - Export + OpUnknown Operation = 0 + Backup Operation = 1 + Restore Operation = 2 + Export Operation = 3 ) // Constructor for ConnectorOperationStatus. If the counts do not agree, an error is returned. diff --git a/src/internal/model/model.go b/src/internal/model/model.go index dcf0dce51..a3f25c820 100644 --- a/src/internal/model/model.go +++ b/src/internal/model/model.go @@ -22,12 +22,12 @@ func (id StableID) String() string { // //go:generate go run golang.org/x/tools/cmd/stringer -type=Schema const ( - UnknownSchema = Schema(iota) - BackupOpSchema - RestoreOpSchema - BackupSchema - BackupDetailsSchema - RepositorySchema + UnknownSchema Schema = 0 + BackupOpSchema Schema = 1 + RestoreOpSchema Schema = 2 + BackupSchema Schema = 3 + BackupDetailsSchema Schema = 4 + RepositorySchema Schema = 5 ) // common tags for filtering @@ -38,7 +38,7 @@ const ( MergeBackup = "merge-backup" ) -// Valid returns true if the ModelType value fits within the iota range. +// Valid returns true if the ModelType value fits within the const range. func (mt Schema) Valid() bool { return mt > 0 && mt < RepositorySchema+1 } diff --git a/src/internal/operations/operation.go b/src/internal/operations/operation.go index 35bf9fb19..c400e52cd 100644 --- a/src/internal/operations/operation.go +++ b/src/internal/operations/operation.go @@ -33,11 +33,11 @@ type OpStatus int //go:generate stringer -type=OpStatus -linecomment const ( - Unknown OpStatus = iota // Status Unknown - InProgress // In Progress - Completed // Completed - Failed // Failed - NoData // No Data + Unknown OpStatus = 0 // Status Unknown + InProgress OpStatus = 1 // In Progress + Completed OpStatus = 2 // Completed + Failed OpStatus = 3 // Failed + NoData OpStatus = 4 // No Data ) // -------------------------------------------------------------------------------- diff --git a/src/pkg/account/account.go b/src/pkg/account/account.go index 12b8d679c..4c1591818 100644 --- a/src/pkg/account/account.go +++ b/src/pkg/account/account.go @@ -10,8 +10,8 @@ type accountProvider int //go:generate stringer -type=accountProvider -linecomment const ( - ProviderUnknown accountProvider = iota // Unknown Provider - ProviderM365 // M365 + ProviderUnknown accountProvider = 0 // Unknown Provider + ProviderM365 accountProvider = 1 // M365 ) // storage parsing errors diff --git a/src/pkg/backup/details/iteminfo.go b/src/pkg/backup/details/iteminfo.go index 9912fb6d2..fbd6a92cd 100644 --- a/src/pkg/backup/details/iteminfo.go +++ b/src/pkg/backup/details/iteminfo.go @@ -20,16 +20,17 @@ type ItemType int // Additionally, any itemType directly assigned a number should not be altered. // This applies to OneDriveItem and FolderItem const ( - UnknownType ItemType = iota // 0, global unknown value + UnknownType ItemType = 0 // Exchange (00x) - ExchangeContact - ExchangeEvent - ExchangeMail + ExchangeContact ItemType = 1 + ExchangeEvent ItemType = 2 + ExchangeMail ItemType = 3 + // SharePoint (10x) - SharePointLibrary ItemType = iota + 97 // 100 - SharePointList // 101... - SharePointPage + SharePointLibrary ItemType = 101 + SharePointList ItemType = 102 + SharePointPage ItemType = 103 // OneDrive (20x) OneDriveItem ItemType = 205 diff --git a/src/pkg/control/repository/repo.go b/src/pkg/control/repository/repo.go index 0d80a1fda..6d1869f91 100644 --- a/src/pkg/control/repository/repo.go +++ b/src/pkg/control/repository/repo.go @@ -25,12 +25,10 @@ type Maintenance struct { type MaintenanceType int -// Can't be reordered as we rely on iota for numbering. -// //go:generate stringer -type=MaintenanceType -linecomment const ( - CompleteMaintenance MaintenanceType = iota // complete - MetadataMaintenance // metadata + CompleteMaintenance MaintenanceType = 0 // complete + MetadataMaintenance MaintenanceType = 1 // metadata ) var StringToMaintenanceType = map[string]MaintenanceType{ @@ -40,16 +38,14 @@ var StringToMaintenanceType = map[string]MaintenanceType{ type MaintenanceSafety int -// Can't be reordered as we rely on iota for numbering. -// //go:generate stringer -type=MaintenanceSafety -linecomment const ( - FullMaintenanceSafety MaintenanceSafety = iota + FullMaintenanceSafety MaintenanceSafety = 0 //nolint:lll // Use only if there's no other kopia instances accessing the repo and the // storage backend is strongly consistent. // https://github.com/kopia/kopia/blob/f9de453efc198b6e993af8922f953a7e5322dc5f/repo/maintenance/maintenance_safety.go#L42 - NoMaintenanceSafety + NoMaintenanceSafety MaintenanceSafety = 1 ) type RetentionMode int diff --git a/src/pkg/path/category_type.go b/src/pkg/path/category_type.go index 4a992176f..5f8009e5d 100644 --- a/src/pkg/path/category_type.go +++ b/src/pkg/path/category_type.go @@ -17,15 +17,15 @@ type CategoryType int //go:generate stringer -type=CategoryType -linecomment const ( - UnknownCategory CategoryType = iota - EmailCategory // email - ContactsCategory // contacts - EventsCategory // events - FilesCategory // files - ListsCategory // lists - LibrariesCategory // libraries - PagesCategory // pages - DetailsCategory // details + UnknownCategory CategoryType = 0 + EmailCategory CategoryType = 1 // email + ContactsCategory CategoryType = 2 // contacts + EventsCategory CategoryType = 3 // events + FilesCategory CategoryType = 4 // files + ListsCategory CategoryType = 5 // lists + LibrariesCategory CategoryType = 6 // libraries + PagesCategory CategoryType = 7 // pages + DetailsCategory CategoryType = 8 // details ) func ToCategoryType(category string) CategoryType { diff --git a/src/pkg/path/service_type.go b/src/pkg/path/service_type.go index 343117857..a4a99ec6c 100644 --- a/src/pkg/path/service_type.go +++ b/src/pkg/path/service_type.go @@ -22,17 +22,17 @@ type ServiceType int //go:generate stringer -type=ServiceType -linecomment const ( - UnknownService ServiceType = iota - ExchangeService // exchange - OneDriveService // onedrive - SharePointService // sharepoint - ExchangeMetadataService // exchangeMetadata - OneDriveMetadataService // onedriveMetadata - SharePointMetadataService // sharepointMetadata - GroupsService // groups - GroupsMetadataService // groupsMetadata - TeamsService // teams - TeamsMetadataService // teamsMetadata + UnknownService ServiceType = 0 + ExchangeService ServiceType = 1 // exchange + OneDriveService ServiceType = 2 // onedrive + SharePointService ServiceType = 3 // sharepoint + ExchangeMetadataService ServiceType = 4 // exchangeMetadata + OneDriveMetadataService ServiceType = 5 // onedriveMetadata + SharePointMetadataService ServiceType = 6 // sharepointMetadata + GroupsService ServiceType = 7 // groups + GroupsMetadataService ServiceType = 8 // groupsMetadata + TeamsService ServiceType = 9 // teams + TeamsMetadataService ServiceType = 10 // teamsMetadata ) func toServiceType(service string) ServiceType { @@ -45,12 +45,20 @@ func toServiceType(service string) ServiceType { return OneDriveService case strings.ToLower(SharePointService.String()): return SharePointService + case strings.ToLower(GroupsService.String()): + return GroupsService + case strings.ToLower(TeamsService.String()): + return TeamsService case strings.ToLower(ExchangeMetadataService.String()): return ExchangeMetadataService case strings.ToLower(OneDriveMetadataService.String()): return OneDriveMetadataService case strings.ToLower(SharePointMetadataService.String()): return SharePointMetadataService + case strings.ToLower(GroupsMetadataService.String()): + return GroupsMetadataService + case strings.ToLower(TeamsMetadataService.String()): + return TeamsMetadataService default: return UnknownService } diff --git a/src/pkg/path/servicetype_string.go b/src/pkg/path/servicetype_string.go index 6fa499364..4b9ab16ec 100644 --- a/src/pkg/path/servicetype_string.go +++ b/src/pkg/path/servicetype_string.go @@ -17,11 +17,13 @@ func _() { _ = x[SharePointMetadataService-6] _ = x[GroupsService-7] _ = x[GroupsMetadataService-8] + _ = x[TeamsService-9] + _ = x[TeamsMetadataService-10] } -const _ServiceType_name = "UnknownServiceexchangeonedrivesharepointexchangeMetadataonedriveMetadatasharepointMetadatagroupsgroupsMetadata" +const _ServiceType_name = "UnknownServiceexchangeonedrivesharepointexchangeMetadataonedriveMetadatasharepointMetadatagroupsgroupsMetadatateamsteamsMetadata" -var _ServiceType_index = [...]uint8{0, 14, 22, 30, 40, 56, 72, 90, 96, 110} +var _ServiceType_index = [...]uint8{0, 14, 22, 30, 40, 56, 72, 90, 96, 110, 115, 128} func (i ServiceType) String() string { if i < 0 || i >= ServiceType(len(_ServiceType_index)-1) { diff --git a/src/pkg/selectors/selectors.go b/src/pkg/selectors/selectors.go index ac85f75c3..3a18c2bd0 100644 --- a/src/pkg/selectors/selectors.go +++ b/src/pkg/selectors/selectors.go @@ -20,11 +20,11 @@ type service int //go:generate stringer -type=service -linecomment const ( - ServiceUnknown service = iota // Unknown Service - ServiceExchange // Exchange - ServiceOneDrive // OneDrive - ServiceSharePoint // SharePoint - ServiceGroups // Groups + ServiceUnknown service = 0 // Unknown Service + ServiceExchange service = 1 // Exchange + ServiceOneDrive service = 2 // OneDrive + ServiceSharePoint service = 3 // SharePoint + ServiceGroups service = 4 // Groups ) var serviceToPathType = map[service]path.ServiceType{ diff --git a/src/pkg/storage/storage.go b/src/pkg/storage/storage.go index 673503587..e197f4081 100644 --- a/src/pkg/storage/storage.go +++ b/src/pkg/storage/storage.go @@ -12,8 +12,8 @@ type storageProvider int //go:generate stringer -type=storageProvider -linecomment const ( - ProviderUnknown storageProvider = iota // Unknown Provider - ProviderS3 // S3 + ProviderUnknown storageProvider = 0 // Unknown Provider + ProviderS3 storageProvider = 1 // S3 ) // storage parsing errors