@@ -86,6 +86,11 @@ function Out-RsFolderContent
86
86
87
87
$Destination = Convert-Path $Destination
88
88
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.
89
94
foreach ($item in $items )
90
95
{
91
96
if (($item.TypeName -eq ' Folder' ) -and $Recurse )
@@ -102,13 +107,18 @@ function Out-RsFolderContent
102
107
New-Item $newFolder - ItemType Directory - Force | Out-Null
103
108
Write-Verbose " Folder: $newFolder was created successfully."
104
109
}
105
-
110
+ } # # End Folder Loop
111
+
112
+ # # Loop for non-folders.
113
+ foreach ($item in $items )
114
+ {
106
115
if ($item.TypeName -eq " Resource" -or
107
116
$item.TypeName -eq " Report" -or
108
117
$item.TypeName -eq " DataSource" -or
109
118
$item.TypeName -eq " DataSet" -or
110
119
$item.TypeName -eq " Component" )
111
120
{
121
+ # TODO: REMOVE this comment below. This is the comment that caused me to look for a solution.
112
122
# We're relying on the fact that the implementation of Get-RsFolderContent will show us the folder before their content,
113
123
# when using the -recurse option, so we can assume that any subfolder will be created before we download the items it contains
114
124
$relativePath = $item.Path
@@ -122,5 +132,5 @@ function Out-RsFolderContent
122
132
$folder = $Destination + $relativePath
123
133
Out-RsCatalogItem - proxy $proxy - RsFolder $item.Path - Destination $folder
124
134
}
125
- }
135
+ } # # End non-Folder loop
126
136
}
0 commit comments