track item size in onedrive restores (#1159)
## Description Hacks in the bytes written as the iteminfo size during onedrive item restores. Would use the drive itemable, but the size property isn't instantiated locally during creation, and cannot be mutated afterwards. ## Type of change - [x] 🐛 Bugfix ## Issue(s) * #1113 ## Test Plan - [x] 💪 Manual
This commit is contained in:
parent
e26a1a7b31
commit
64219c3ae7
@ -125,7 +125,10 @@ func getFolder(ctx context.Context, service graph.Service, driveID string, paren
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new item in the specified folder
|
// Create a new item in the specified folder
|
||||||
func createItem(ctx context.Context, service graph.Service, driveID string, parentFolderID string,
|
func createItem(
|
||||||
|
ctx context.Context,
|
||||||
|
service graph.Service,
|
||||||
|
driveID, parentFolderID string,
|
||||||
newItem models.DriveItemable,
|
newItem models.DriveItemable,
|
||||||
) (models.DriveItemable, error) {
|
) (models.DriveItemable, error) {
|
||||||
// Graph SDK doesn't yet provide a POST method for `/children` so we set the `rawUrl` ourselves as recommended
|
// Graph SDK doesn't yet provide a POST method for `/children` so we set the `rawUrl` ourselves as recommended
|
||||||
|
|||||||
@ -60,24 +60,31 @@ func driveItemReader(
|
|||||||
return nil, nil, errors.Wrapf(err, "failed to download file from %s", *downloadURL)
|
return nil, nil, errors.Wrapf(err, "failed to download file from %s", *downloadURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
return driveItemInfo(item), resp.Body, nil
|
return driveItemInfo(item, *item.GetSize()), resp.Body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// driveItemInfo will populate a details.OneDriveInfo struct
|
// driveItemInfo will populate a details.OneDriveInfo struct
|
||||||
// with properties from the drive item.
|
// with properties from the drive item. ItemSize is specified
|
||||||
func driveItemInfo(di models.DriveItemable) *details.OneDriveInfo {
|
// 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.
|
||||||
|
func driveItemInfo(di models.DriveItemable, itemSize int64) *details.OneDriveInfo {
|
||||||
return &details.OneDriveInfo{
|
return &details.OneDriveInfo{
|
||||||
ItemType: details.OneDriveItem,
|
ItemType: details.OneDriveItem,
|
||||||
ItemName: *di.GetName(),
|
ItemName: *di.GetName(),
|
||||||
Created: *di.GetCreatedDateTime(),
|
Created: *di.GetCreatedDateTime(),
|
||||||
Modified: *di.GetLastModifiedDateTime(),
|
Modified: *di.GetLastModifiedDateTime(),
|
||||||
Size: *di.GetSize(),
|
Size: itemSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// driveItemWriter is used to initialize and return an io.Writer to upload data for the specified item
|
// driveItemWriter is used to initialize and return an io.Writer to upload data for the specified item
|
||||||
// It does so by creating an upload session and using that URL to initialize an `itemWriter`
|
// It does so by creating an upload session and using that URL to initialize an `itemWriter`
|
||||||
func driveItemWriter(ctx context.Context, service graph.Service, driveID, itemID string, itemSize int64,
|
func driveItemWriter(
|
||||||
|
ctx context.Context,
|
||||||
|
service graph.Service,
|
||||||
|
driveID, itemID string,
|
||||||
|
itemSize int64,
|
||||||
) (io.Writer, error) {
|
) (io.Writer, error) {
|
||||||
// TODO: @vkamra verify if var session is the desired input
|
// TODO: @vkamra verify if var session is the desired input
|
||||||
session := msup.NewCreateUploadSessionPostRequestBody()
|
session := msup.NewCreateUploadSessionPostRequestBody()
|
||||||
|
|||||||
@ -251,10 +251,10 @@ func restoreItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Upload the stream data
|
// Upload the stream data
|
||||||
_, err = io.CopyBuffer(w, itemData.ToReader(), copyBuffer)
|
written, err := io.CopyBuffer(w, itemData.ToReader(), copyBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to upload data: item %s", itemName)
|
return nil, errors.Wrapf(err, "failed to upload data: item %s", itemName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return driveItemInfo(newItem), nil
|
return driveItemInfo(newItem, written), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user