dsccommunity / xRobocopy

DSC Module to automate Robocopy transfers
MIT License
54 stars 15 forks source link

Why does most errorcodes return $false? #29

Open nicolas6969 opened 6 years ago

nicolas6969 commented 6 years ago

We are using the xRobocopy module to copy various files/folders from different sources to one same destination. As the destination is never in sync with the different sources, the returned errorcode is always 3 (when at least one file has been copied) or 2 (when no files have been copied), because there are always extra files detected).

We have tried using /XX, but it doesn't affect the returned errorcode. Unfortunately, the resource gives back $false, as soon as the returned errorcode is not 0. So as long as extra file/folders are detected in destination, Test-DscConfiguration returns the related resources as not in desired state.

From our perspective, the extra files/folders (errorcodes 2 and 3) should result in "in desired state", so the resource test should return $true. Is there a way to accomplish this?

Or is this maybe an issue related to robocopy.exe, as the flag /XX should return errorcode 0 although extra folders/files are detected?

johlju commented 6 years ago

It seems that currently the resource expects that the destination folder is fully synchronized and does not have extra folders and files. Doesn't look like there are parameters to handle your case. I think there need to be new boolean parameters to control what error codes are accepted and should return $true or $false. Like AllowExtraFoldersInDestination, AllowExtraFilesInDestination, if that is a possibility.

nicolas6969 commented 6 years ago

Thanks a lot for the feedback.

Maybe the resource should be updated to not return $false, if the errorcode is not greater than 8. Microsoft says on https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

image

So that means every error code less or equal 8 is not an error?!

johlju commented 6 years ago

If there are errors during copy operation then the Set-TargetResource should throw an error. The Test-TargetResource does not do any actual copy operation but validates what the state would be if it would do a copy operation. Not sure it should return $false if that returns that it could not copy at all, then I think Test-TargetResource should throw also.

Some user might want it to return false if there are added files in the destination, because there should be no extra files or folders in the destination so they want to purge those. So the resource need to have a way to support several scenarios, that is does not have today.

jberezanski commented 3 years ago

The user intent could be deduced from arguments passed to robocopy. Specifically, /MIR or /PURGE instruct robocopy to remove extra files, so the resource could treat exit code 2 as compliant if those arguments are not present.