Skip to content

Commit

Permalink
!deploy v2.22.2 to resolve #144
Browse files Browse the repository at this point in the history
## 2.22.2

* [Issue #144](#144)
  * Updated: `Start-GSDriveFileUpload` to `Dispose()` open streams once uploads are completed.
  * Added: `Stop-GSDriveFileUpload` to enable cleanup of any remaining open streams.
  * Updated: `Get-GSDriveFileUpload` to `Dispose()` any completed streams that are still open.
  • Loading branch information
scrthq authored Jan 15, 2019
2 parents b94bd96 + 0f4d20a commit 5e1d3a8
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 359 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

* [Changelog](#changelog)
* [2.22.2](#2222)
* [2.22.1](#2221)
* [2.22.0](#2220)
* [2.21.3](#2213)
Expand Down Expand Up @@ -70,6 +71,13 @@

***

## 2.22.2

* [Issue #144](https://github.com/scrthq/PSGSuite/issues/144)
* Updated: `Start-GSDriveFileUpload` to `Dispose()` open streams once uploads are completed.
* Added: `Stop-GSDriveFileUpload` to enable cleanup of any remaining open streams.
* Updated: `Get-GSDriveFileUpload` to `Dispose()` any completed streams that are still open.

## 2.22.1

* [PR #141](https://github.com/scrthq/PSGSuite/pull/141) - _Thanks, [@dwrusse](https://github.com/dwrusse)!_
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.22.1'
ModuleVersion = '2.22.2'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
92 changes: 49 additions & 43 deletions PSGSuite/Public/Drive/Get-GSDriveFileUploadStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ function Get-GSDriveFileUploadStatus {
<#
.SYNOPSIS
Gets the current Drive file upload status
.DESCRIPTION
Gets the current Drive file upload status
.PARAMETER Id
The upload Id for the task you'd like to retrieve the status of
.PARAMETER InProgress
If passed, only returns upload statuses that are not 'Failed' or 'Completed'. If nothing is returned when passing this parameter, all tracked uploads have stopped
.EXAMPLE
Get-GSDriveFileUploadStatus -InProgress
Expand All @@ -35,6 +35,16 @@ function Get-GSDriveFileUploadStatus {
foreach ($task in $script:DriveUploadTasks) {
$elapsed = ((Get-Date) - $task.StartTime)
$progress = {$task.Request.GetProgress()}.InvokeReturnAsIs()
if (-not $task.StreamDisposed -and $progress.Status -eq 'Completed') {
try {
Write-Verbose "[$($progress.Status)] Disposing stream of Task Id [$($task.Id)] | File [$($task.File.FullName)]"
$task.Stream.Dispose()
$task.StreamDisposed = $true
}
catch {
Write-Error $_
}
}
$bytesSent = $progress.BytesSent
$remaining = try {
New-TimeSpan -Seconds $(($elapsed.TotalSeconds / ($bytesSent / ($task.Length))) - $elapsed.TotalSeconds) -ErrorAction Stop
Expand All @@ -48,49 +58,45 @@ function Get-GSDriveFileUploadStatus {
else {
0
}
if ($Id) {
if ($Id -contains $task.Id) {
$obj = [PSCustomObject]@{
Id = $task.Id
Status = $progress.Status
PercentComplete = $percentComplete
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
}
if (!$InProgress -or $obj.Status -notin @('Failed','Completed')) {
$obj
if (-not $InProgress -or $progress.Status -notin @('Failed','Completed')) {
if ($Id) {
if ($Id -contains $task.Id) {
[PSCustomObject]@{
Id = $task.Id
Status = $progress.Status
PercentComplete = $percentComplete
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
}
}
}
}
else {
$obj = [PSCustomObject]@{
Id = $task.Id
Status = $progress.Status
PercentComplete = $percentComplete
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
}
if (!$InProgress -or $obj.Status -notin @('Failed','Completed')) {
$obj
else {
[PSCustomObject]@{
Id = $task.Id
Status = $progress.Status
PercentComplete = $percentComplete
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
}
}
}
}
}
}
}
}
Loading

0 comments on commit 5e1d3a8

Please sign in to comment.