KNOXDEV / scoop-backup

Backup your entire current scoop installation with one command
The Unlicense
60 stars 6 forks source link

Error when saving backup to custom folder #1

Closed graphixillusion closed 4 years ago

graphixillusion commented 4 years ago

As the Title says i got this error when i try to save the backup script to a custom folder:

New-Item : Access to path 'C:\temp' denied.
In C:\Users\USER\scoop\apps\scoop-backup\current\scoop-backup.ps1:102 car:1
+ New-Item $destination -Force | Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\temp:String) [New-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

Add-Content : Access to path 'C:\temp' denied.
In C:\Users\USER\scoop\apps\scoop-backup\current\scoop-backup.ps1:109 car:5
+     Add-Content -Path $destination -Value $cmd_encoded
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\temp:String) [Add-Content], UnauthorizedAccessException
    + FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand

of course the current user has rights to access that dir and i got the same result running everything as administrators. OS: Win 10 Pro version 1903

graphixillusion commented 4 years ago

Awaiting for an official answer, i've made this modification to the code and with this i have no more errors:

New-Item $destination -Name $default_file -Force | Out-Null
if($compressed) {
    $cmd_bytes = [System.Text.Encoding]::Unicode.GetBytes($cmd)
    $cmd_encoded = '@echo off' + [environment]::NewLine `
                + "powershell.exe -NoProfile -EncodedCommand " `
                + [Convert]::ToBase64String($cmd_bytes) + [environment]::NewLine `
                + 'pause'
    Add-Content -Path $destination\$default_file -Value $cmd_encoded
} else {
    Add-Content -Path $destination\$default_file -Value $cmd
}

As you can see i simply added:

respectively to the New-Item and Add-Content commands. The only little issue i've found with this code is that when you choose to backup to the default path, the script always creates backupname.ext\backupname.ext (script file inside a dir with the same name) and i can't understand why. As i said, this happens only when you choose the default path. With custom paths works as it should.

KNOXDEV commented 4 years ago

Thanks for bringing this to my attention. I addressed this in a slightly different way and I added some more verbose handling of other custom directory edge cases.

graphixillusion commented 4 years ago

Thank you for fixing. You should do this change too:

WARN  "buckets" will be deprecated. Please change your code/manifest to use "Get-LocalBucket"
      -> C:\Users\USER\scoop\apps\scoop-backup\current\scoop-backup.ps1:64:12
WARN  "buckets" will be deprecated. Please change your code/manifest to use "Get-LocalBucket"
      -> C:\Users\USER\scoop\apps\scoop-backup\current\scoop-backup.ps1:69:5
KNOXDEV commented 4 years ago

Done, see e2522e0686088c13d61042282531d5b4a4995c65 Please open a separate issue next time, it makes tracking easier.