Skip to content

Commit 972209c

Browse files
Merge pull request #48 from mgr32/dev
Added MatchSource parameter to xRemoteFile. Fixes #45
2 parents 6157597 + 2a84581 commit 972209c

3 files changed

Lines changed: 45 additions & 23 deletions

File tree

DSCResources/MSFT_xRemoteFile/MSFT_xRemoteFile.psm1

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ function Set-TargetResource
100100
$Headers,
101101

102102
[System.Management.Automation.PSCredential]
103-
$Credential
103+
$Credential,
104+
105+
[parameter(Mandatory = $false)]
106+
[System.Boolean]
107+
$MatchSource = $true
104108
)
105109

106110
# Validate Uri
@@ -154,8 +158,9 @@ function Set-TargetResource
154158
$DestinationPath = Join-Path $DestinationPath $uriFileName
155159
}
156160

157-
# Remove DestinationPath from parameters as it is not parameter of Invoke-WebRequest
161+
# Remove DestinationPath and MatchSource from parameters as they are not parameters of Invoke-WebRequest
158162
$PSBoundParameters.Remove("DestinationPath") | Out-Null;
163+
$PSBoundParameters.Remove("MatchSource") | Out-Null;
159164

160165
# Convert headers to hashtable
161166
$PSBoundParameters.Remove("Headers") | Out-Null;
@@ -216,7 +221,11 @@ function Test-TargetResource
216221
$Headers,
217222

218223
[System.Management.Automation.PSCredential]
219-
$Credential
224+
$Credential,
225+
226+
[parameter(Mandatory = $false)]
227+
[System.Boolean]
228+
$MatchSource = $true
220229
)
221230

222231
# Check whether DestinationPath points to existing file or directory
@@ -228,37 +237,47 @@ function Test-TargetResource
228237
"File" {
229238
Write-Debug "DestinationPath: '$DestinationPath' is existing file on the machine"
230239

231-
$file = Get-Item $DestinationPath
232-
# Getting cache. It's cleared every time user runs Start-DscConfiguration
233-
$cache = Get-Cache -DestinationPath $DestinationPath -Uri $Uri
240+
if ($MatchSource) {
241+
$file = Get-Item $DestinationPath
242+
# Getting cache. It's cleared every time user runs Start-DscConfiguration
243+
$cache = Get-Cache -DestinationPath $DestinationPath -Uri $Uri
234244

235-
if ($cache -ne $null -and ($cache.LastWriteTime -eq $file.LastWriteTimeUtc))
236-
{
237-
Write-Debug "Cache reflects current state. No need for downloading file."
238-
$fileExists = $true
245+
if ($cache -ne $null -and ($cache.LastWriteTime -eq $file.LastWriteTimeUtc))
246+
{
247+
Write-Debug "Cache reflects current state. No need for downloading file."
248+
$fileExists = $true
249+
}
250+
else
251+
{
252+
Write-Debug "Cache is empty or it doesn't reflect current state. File will be downloaded."
253+
}
254+
} else {
255+
Write-Debug "MatchSource is false. No need for downloading file."
256+
$fileExists = $true
239257
}
240-
else
241-
{
242-
Write-Debug "Cache is empty or it doesn't reflect current state. File will be downloaded."
243-
}
244258
}
245259

246260
"Directory" {
247261
Write-Debug "DestinationPath: '$DestinationPath' is existing directory on the machine"
248262
$expectedDestinationPath = Join-Path $DestinationPath $uriFileName
249263

250264
if (Test-Path $expectedDestinationPath) {
251-
$file = Get-Item $expectedDestinationPath
252-
$cache = Get-Cache -DestinationPath $expectedDestinationPath -Uri $Uri
253-
if ($cache -ne $null -and ($cache.LastWriteTime -eq $file.LastWriteTimeUtc))
254-
{
255-
Write-Debug "Cache reflects current state. No need for downloading file."
265+
if ($MatchSource) {
266+
$file = Get-Item $expectedDestinationPath
267+
$cache = Get-Cache -DestinationPath $expectedDestinationPath -Uri $Uri
268+
if ($cache -ne $null -and ($cache.LastWriteTime -eq $file.LastWriteTimeUtc))
269+
{
270+
Write-Debug "Cache reflects current state. No need for downloading file."
271+
$fileExists = $true
272+
}
273+
else
274+
{
275+
Write-Debug "Cache is empty or it doesn't reflect current state. File will be downloaded."
276+
}
277+
} else {
278+
Write-Debug "MatchSource is false. No need for downloading file."
256279
$fileExists = $true
257280
}
258-
else
259-
{
260-
Write-Debug "Cache is empty or it doesn't reflect current state. File will be downloaded."
261-
}
262281
}
263282
}
264283

DSCResources/MSFT_xRemoteFile/MSFT_xRemoteFile.schema.mof

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class MSFT_xRemoteFile : OMI_BaseResource
77
[Write, Description("User agent for the web request.")] String UserAgent;
88
[Write, EmbeddedInstance("MSFT_KeyValuePair"), Description("Headers of the web request.")] String Headers[];
99
[Write, EmbeddedInstance("MSFT_Credential"), Description("Specifies a user account that has permission to send the request.")] String Credential;
10+
[Write, Description("A boolean value to indicate whether the remote file should be re-downloaded if file in the DestinationPath was modified locally.")] Boolean MatchSource;
1011
[Read, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Says whether DestinationPath exists on the machine")] String Ensure;
1112
};
1213

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ For a complete list of properties, please use Get-DscResource
6868
* **UserAgent**: User agent for the web request.
6969
* **Headers**: Headers of the web request.
7070
* **Credential**: Specifies credential of a user which has permissions to send the request.
71+
* **MatchSource**: Determines whether the remote file should be re-downloaded if file in the DestinationPath was modified locally.
7172
* **Ensure**: Says whether DestinationPath exists on the machine. It's a read only property.
7273

7374
### xPackage
@@ -136,6 +137,7 @@ Domain members may be specified using domain\name or Universal Principal Name (U
136137
### Unreleased
137138

138139
* Added CreateCheckRegValue parameter to xPackage resource
140+
* Added MatchSource parameter to xRemoteFile resource
139141

140142
### 3.5.0.0
141143

0 commit comments

Comments
 (0)