1
+ param (
2
+ [Parameter (Mandatory = $true )]
3
+ $Configuraton )
4
+
5
+ $ErrorActionPreference = " Stop"
6
+ $scriptpath = $MyInvocation.MyCommand.Path
7
+ $scriptDirectory = Split-Path $scriptpath
8
+ $scriptFileName = Split-Path $scriptpath - Leaf
9
+
10
+ if (gcm Invoke-AzureRmStorageSyncCompatibilityCheck - ErrorAction SilentlyContinue)
11
+ {
12
+ throw " Invoke-AzureRmStorageSyncCompatibilityCheck is already available. Cannot continue with module debugging."
13
+ }
14
+
15
+ $azProfilePath = Join-Path $scriptDirectory " ..\..\..\..\src\Package\$Configuraton \ResourceManager\AzureResourceManager\Az.Profile\Az.Profile.psd1"
16
+ Import-Module $azProfilePath - Verbose
17
+
18
+ $azStorageSyncPath = Join-Path $scriptDirectory " ..\..\..\..\src\Package\$Configuraton \ResourceManager\AzureResourceManager\Az.StorageSync\Az.StorageSync.psd1"
19
+ Import-Module $azStorageSyncPath - Verbose
20
+
21
+ $VerbosePreference = ' Continue'
22
+
23
+ function prompt { return " PS> " }
24
+
25
+ Write-Verbose ' Your debugger is attached to current PowerShell instance'
26
+ Write-Verbose ' To recreate a test data set and perform an evaluation run'
27
+ Write-Verbose ' Perform-Test -Full'
28
+ Write-Verbose ' To perform an evaluation for an already created dataset run'
29
+ Write-Verbose ' Perform-Test'
30
+ Write-Verbose ' Use Get-DataSetLocation to find location of the dataset'
31
+
32
+ function Get-Configuration
33
+ {
34
+ Get-Content - Raw - Path (Join-Path $scriptDirectory " config.json" ) | ConvertFrom-Json
35
+ }
36
+
37
+ function Build-CharacterTable
38
+ {
39
+ param ($Configuration )
40
+
41
+ $blacklistOfCodePoints = $Configuration.BlacklistOfCodePoints
42
+ $whitelistOfCodePointRanges = $Configuration.WhitelistOfCodePointRanges
43
+
44
+ $arraySize = 0x10FFFF + 1
45
+ $blacklistedCodePointsTable = new-object bool[] $arraySize
46
+ for ($i = 0 ; $i -lt $arraySize ; $i += 1 )
47
+ {
48
+ $blacklistedCodePointsTable [$i ] = $blacklistOfCodePoints.Contains ($i ) -or
49
+ ($whitelistOfCodePointRanges.Where ({ ($_.Start -le $i ) -and ($_.End -ge $i ) }).Count -eq 0 );
50
+ }
51
+ return $blacklistedCodePointsTable
52
+ }
53
+
54
+ function CreateItem
55
+ {
56
+ param ($path , $name , $itemType )
57
+
58
+ $fullpath = Join-Path $path $name
59
+
60
+ try
61
+ {
62
+ if (Test-Path $fullpath )
63
+ {
64
+ return
65
+ }
66
+
67
+ if (! (Test-Path $path ))
68
+ {
69
+ New-Item - Path $path - ItemType Directory | Out-Null
70
+ }
71
+
72
+ New-Item - Path $path - Name $name - ItemType $itemType | Out-Null
73
+ }
74
+ catch
75
+ {
76
+ throw " Couldn't handle path:$path , name:$name , itemType:$itemType "
77
+ }
78
+ }
79
+
80
+ function CreateItemsWithInvalidCharacters
81
+ {
82
+ param ($path , $configuration , $blockedCharactersTable , $itemType )
83
+
84
+ Write-Verbose " Creating items of type $itemType with invalid characters"
85
+ $skippedCodePoints = 0
86
+ $succeededCodePoints = 0
87
+ for ($i = 0 ; $i -lt $blockedCharactersTable.Count ; $i += 1 )
88
+ {
89
+ $isBlocked = $blockedCharactersTable [$i ];
90
+ if ($isBlocked )
91
+ {
92
+ $invalid_character_or_surrogate_pair = " <unavailable>"
93
+ try
94
+ {
95
+ $invalid_character_or_surrogate_pair = [char ]::ConvertFromUtf32($i )
96
+ if ($invalid_character_or_surrogate_pair.Length -gt 1 )
97
+ {
98
+ CreateItem - path $path - name (" {1}invalidSurrogatePair_occurence1_{0}_occurence2_{0}" -f $invalid_character_or_surrogate_pair , $itemType ) - itemType $itemType
99
+ }
100
+ else
101
+ {
102
+ CreateItem - path $path - name (" {1}invalidChar_occurence1_{0}_occurence2_{0}" -f $invalid_character_or_surrogate_pair , $itemType ) - itemType $itemType
103
+ }
104
+ $succeededCodePoints += 1
105
+ }
106
+ catch
107
+ {
108
+ Write-Warning (" Skipping blocked codepoint #{0} as hex 0x{0:X} '{1}' : blocked '{2}'. Error: {3}" -f $i , $invalid_character_or_surrogate_pair , $isBlocked , $_ )
109
+ $skippedCodePoints += 1
110
+ }
111
+ }
112
+ }
113
+
114
+ Write-Verbose " Created $succeededCodePoints items, skipped $skippedCodePoints "
115
+ }
116
+
117
+ function Ensure-RobocopySampleLocation
118
+ {
119
+ $sampleDir = Join-Path $env: TEMP " robocopy-sample"
120
+
121
+ if (Test-Path $sampleDir )
122
+ {
123
+ Remove-Item $sampleDir - Recurse | Out-Null
124
+ }
125
+
126
+ New-Item $sampleDir - ItemType Directory | Out-Null
127
+
128
+ return $sampleDir
129
+ }
130
+
131
+ function CreateDirectoryWithRobocopy
132
+ {
133
+ param ($targetDir )
134
+
135
+ $sampleDir = Ensure- RobocopySampleLocation
136
+
137
+ Write-Verbose " . robocopy.exe $sampleDir $targetDir /MIR"
138
+
139
+ . robocopy.exe $sampleDir $targetDir / MIR
140
+ }
141
+
142
+ function Get-DataSetLocation
143
+ {
144
+ return Join-Path $env: TEMP " EvalToolDataSet"
145
+ }
146
+
147
+ function Clear-DataSetLocation
148
+ {
149
+ CreateDirectoryWithRobocopy - targetDir (Get-DataSetLocation )
150
+ }
151
+
152
+ function Perform-Test
153
+ {
154
+ param ([switch ]$Full , [switch ]$SkipInvalidCharacters , [switch ]$TrailingSlash , [switch ]$AlternateSlash )
155
+
156
+ $dataSetLocation = Get-DataSetLocation
157
+ $dataSetLocationForTest = $dataSetLocation
158
+
159
+ $slashCharacter = if ($AlternateSlash ) { " /" } else { " \" }
160
+
161
+ if ($TrailingSlash )
162
+ {
163
+ $dataSetLocationForTest = " $ ( $dataSetLocation ) $ ( $slashCharacter ) "
164
+ }
165
+
166
+ if ($AlternateSlash )
167
+ {
168
+ $dataSetLocationForTest = $dataSetLocationForTest.Replace (" \" , $slashCharacter )
169
+ $dataSetLocationForTest = $dataSetLocationForTest.Replace (" /" , $slashCharacter )
170
+ }
171
+
172
+ if ($Full )
173
+ {
174
+ Write-Verbose " Getting configuration"
175
+ $configuration = Get-Configuration
176
+
177
+ if (! $SkipInvalidCharacters )
178
+ {
179
+ Write-Verbose " Creating blocked character table"
180
+ $table = Build-CharacterTable - Configuration $configuration
181
+
182
+ Write-Verbose " Creating invalid files"
183
+ $pathForInvalidFileNameCharacters = Join-Path $dataSetLocation " InvalidFileNameCharacters"
184
+ CreateItemsWithInvalidCharacters - path $pathForInvalidFileNameCharacters - configuration $configuration - blockedCharactersTable $table - itemType File
185
+
186
+ Write-Verbose " Creating invalid dirs"
187
+ $pathForInvalidDirNameCharacters = Join-Path $dataSetLocation " InvalidDirNameCharacters"
188
+ CreateItemsWithInvalidCharacters - path $pathForInvalidDirNameCharacters - configuration $configuration - blockedCharactersTable $table - itemType Directory
189
+ }
190
+ else
191
+ {
192
+ Write-Verbose " Skip invalid characters dataset creation"
193
+ }
194
+
195
+ Write-Verbose " Creating directory violating depth requirement"
196
+ $pathWithInvalidDepth = " x\" * 300
197
+ CreateDirectoryWithRobocopy - targetDir (Join-Path (Get-DataSetLocation ) $pathWithInvalidDepth )
198
+
199
+ Write-Verbose " Creating directory violating max path requirement"
200
+ $pathWithInvalidFileName = " maximum path length validation\" * 70
201
+ CreateDirectoryWithRobocopy - targetDir (Join-Path (Get-DataSetLocation ) $pathWithInvalidFileName )
202
+ }
203
+ else
204
+ {
205
+ if (! (Test-Path $dataSetLocation ))
206
+ {
207
+ throw " Cannot access: $dataSetLocation "
208
+ }
209
+ }
210
+
211
+ Write-Verbose " Invoking evaluation tool with path $dataSetLocation "
212
+ $result = Invoke-AzStorageSyncCompatibilityCheck - Path $dataSetLocationForTest - SkipSystemChecks
213
+
214
+ # displaying report
215
+ $result | Format-Custom
216
+
217
+ # handling check results
218
+ $results = $result.Results
219
+ Write-Verbose " Number of results: $ ( $results.Count ) "
220
+
221
+ $reportLocation = Join-Path $env: TEMP " EvalReport.csv"
222
+ Write-Verbose " Exporting as CSV at $reportLocation "
223
+ $results | Select-Object - Property Type, Path, Level, Description, Result | Export-Csv - Path $reportLocation - NoTypeInformation - Encoding Utf8
224
+
225
+ Write-Verbose " Done"
226
+ }
0 commit comments