Skip to content

Commit 994779b

Browse files
authored
Merge pull request microsoft#281 from matrix75/master
Update Out-RsFolderContent.ps1
2 parents f4677b9 + f65506e commit 994779b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ReportingServicesTools/Functions/CatalogItems/Out-RsFolderContent.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ function Out-RsFolderContent
8686

8787
$Destination = Convert-Path $Destination
8888

89+
## Loop for folders first, because we need to ensure folders are written to disk before we
90+
## attempt to write any files. Otherwise, file writes will randomly fail to write because
91+
## its folder has not been created yet.
92+
## The Solution was to loop and create all folders then work on the files.
93+
## Basically, create all folders, then write all the files.
8994
foreach ($item in $items)
9095
{
9196
if (($item.TypeName -eq 'Folder') -and $Recurse)
@@ -102,13 +107,18 @@ function Out-RsFolderContent
102107
New-Item $newFolder -ItemType Directory -Force | Out-Null
103108
Write-Verbose "Folder: $newFolder was created successfully."
104109
}
105-
110+
} ## End Folder Loop
111+
112+
## Loop for non-folders.
113+
foreach ($item in $items)
114+
{
106115
if ($item.TypeName -eq "Resource" -or
107116
$item.TypeName -eq "Report" -or
108117
$item.TypeName -eq "DataSource" -or
109118
$item.TypeName -eq "DataSet" -or
110119
$item.TypeName -eq "Component")
111120
{
121+
# TODO: REMOVE this comment below. This is the comment that caused me to look for a solution.
112122
# We're relying on the fact that the implementation of Get-RsFolderContent will show us the folder before their content,
113123
# when using the -recurse option, so we can assume that any subfolder will be created before we download the items it contains
114124
$relativePath = $item.Path
@@ -122,5 +132,5 @@ function Out-RsFolderContent
122132
$folder = $Destination + $relativePath
123133
Out-RsCatalogItem -proxy $proxy -RsFolder $item.Path -Destination $folder
124134
}
125-
}
135+
} ## End non-Folder loop
126136
}

0 commit comments

Comments
 (0)