Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Action Rename and -Action Delete fail if the file name contains square brackets. #6

Open
TheRedeemer opened this issue Jan 23, 2022 · 1 comment

Comments

@TheRedeemer
Copy link

I have a solution that may resolve this, but here is the issue first from a test run:

PS C:\working_directory\Documents> Start-PsFCIV -Path .\ -XML "C:\working_directory\DB.xml" -HashAlgorithm SHA256 -Recur
se -Verbose -Debug -Action Rename
DEBUG: Native PsFCIV mode ON
VERBOSE: Perform file 'Directory1\Another Test File.txt' checking.
DEBUG: Selected hash name : SHA256
DEBUG: Selected hash value: 6978413F9D61E2AA69A31CB7750B80B7FFF5C9F9DF5336A1D0612EFB6C54A58A
DEBUG: File hash: 6978413F9D61E2AA69A31CB7750B80B7FFF5C9F9DF5336A1D0612EFB6C54A58A
VERBOSE: File 'Another Test File.txt' is ok.
VERBOSE: Perform file 'a text file.txt' checking.
DEBUG: Selected hash name : SHA256
DEBUG: Selected hash value: 837CCB607E312B170FAC7383D7CCFD61FA5072793F19A25E75FBACB56539B86B
DEBUG: File hash: 837CCB607E312B170FAC7383D7CCFD61FA5072793F19A25E75FBACB56539B86B
VERBOSE: File 'a text file.txt' is ok.
VERBOSE: Perform file '[Torgo].gif' checking.
DEBUG: Selected hash name : SHA256
DEBUG: Selected hash value: 0201C1264D23B9EA3183CF5AFA953CA470A3A786F79B039C84C0AB05FEF171AC
DEBUG: File '[Torgo].gif' failed hash verification.
                Expected hash: @{HashName=System.String[];
HashValue=0201C1264D23B9EA3183CF5AFA953CA470A3A786F79B039C84C0AB05FEF171AC}.HashValue
                Actual hash: 7C462C54798E9CA1A737A91E7F4B120460EF8754D00B7F7A1FFE09F395F1AFBC
Rename-Item : Cannot rename because item at 'C:\working_directory\Documents\[Torgo].gif' does not exist.
At C:\Program Files\WindowsPowerShell\Modules\PsFCIV\1.1\PsFCIV.psm1:95 char:19
+         "Rename" {Rename-Item $file $($file.FullName + ".bad")}
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand

-----------------------------------
Total files processed      : 3
Total good files           : 2
Total bad files            : 1
Total unknown status files : 0
Total missing files        : 0
Total locked files         : 0
-----------------------------------


Total   : 3
New     : 0
Ok      : 2
Bad     : 1
Missed  : 0
Locked  : 0
Unknown : 0
Deleted : 0

It would seem that both the Rename-Item and Remove-Item cmdlets require the -LiteralPath paramenter to be able to interpret square brackets or other special characters.

I would suggest modifying this function:

# process -Action parameter to perform an action against bad file (if actual file properties do not match the record in XML).

possible changes below. I have also included two calls to Write-Verbose since I feel better knowing when a file is being modified.

# process -Action parameter to perform an action against bad file (if actual file properties do not match the record in XML).
function __takeAction ($file, $Action) {
    switch ($Action) {
        "Rename" {
            Write-Verbose "Action: Rename file '$file' to '$($file.FullName + ".bad")'"
            Rename-Item -LiteralPath $file -NewName $($file.FullName + ".bad")
         }
        "Delete" {
            Write-Verbose "Action: Delete file '$file'"
            Remove-Item -LiteralPath $file -Force
         }
    }
}

Would it be possible to push version 1.2 to the powershell gallery later? It makes managing versions and re-deployment a bit easier. Thank You!

working_directory.zip

@TheRedeemer
Copy link
Author

With the latest commits I have been able to process / verify / re-build / re-veritfy all my remaining data sets successfully.

Everything is working so well that there is nothing else on my wish list.

Maybe if you can also change the wording of this line of output before the next release:

Write-Debug "Preparing to DataBase file creation..."

NEW:
        Write-Debug "Writing to XML DataBase file..."

Thanks again for all your hard work on this application. I'm happy to say goodbye to microsoft fciv. Your PsFCIV is so much more versatile and useful with its wide array of secure hashing algorithms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant