-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[WIP] Persistence rework with backward compatibility (persist) #3212
base: master
Are you sure you want to change the base?
Conversation
- Add is_junction() - Add create_junction() - Add remove_junction() - Add create_hardlink() - Add remove_hardlink()
- Extract old persist_data() functionality for backwards compatible with old manifests - Introduce new persist_data_new() stub
- Deprecates the String representation - Deprecates the StringArray representation - Introduces first version of Object representation
"enum": [ | ||
"file", | ||
"directory", | ||
"folder" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why both folder and directory? Is it just alias or some actual differences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, might drop it. Only directory
should be fine.
Small notes without code review: Make encoding UTF8 encoding default in code (eg. When not specified, use UTF-8), same for method link. |
|
||
function create_junction([String] $link, [String] $target) { | ||
if (!(Test-Path $link) -and (is_directory $target)) { | ||
New-Item -ItemType Junction -Path (Split-Path -Path $link) -Name (Split-Path -Leaf $link) -Target $target | Out-Null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is needless to seperate Path and Name (refer to New-Item doc
"required": [ | ||
"encoding", | ||
"content" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two properties should not be required, they could be ommited in most instances with no contents and encoding "UTF-8" (which is default in Windows 10 in despite of encoding with Default, ASCII, OEM in Out-File, but "UTF8" give "UTF-8 with BOM"...).
If app require different encoding, we can set through Get-Content | Out-File -Encoding, but it should be rare case.
{ | ||
"description": "Deprecated, use object representation instead.", | ||
"items": { | ||
"$ref": "#/definitions/stringOrArrayOfStrings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have #/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings, why not using it as former?
if(is_junction $link) { | ||
$dirInfo = New-Object System.IO.DirectoryInfo($link) | ||
$dirInfo.Attributes = $dirInfo.Attributes -band (-bnot [System.IO.FileAttributes]::ReadOnly) | ||
$dirInfo.Delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove-Item xxx -Recurse -Force could remove read-only junction. So if we want to delete junction or hardlink, a single function that Remove-Item xxx -Recurse -Force is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I got an error message saying powershell is not in interactive mode, so I changed it to a simple delete be the object is already there.
Sent from my OnePlus5T using FastHub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested with changing two remove_
function's contents to Remove-Item
(after fix typo in L1216), and also with replacing all remove_junction
and remove_hardlink
with Remove-Item xxx -Recurse -Force | Out-Null
(with a file existing check in link_current
), and gotten no error. Maybe need more test.
PS. I've googled that without -Force
may return the error that not in interactive mode
. May help.
attrib -R /L $filepath | ||
# remove the junction | ||
& "$env:COMSPEC" /c "rmdir /s /q $filepath" | ||
remove_junction | Out-Null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo: missing $filename
if(is_junction $link) { | ||
$dirInfo = New-Object System.IO.DirectoryInfo($link) | ||
$dirInfo.Attributes = $dirInfo.Attributes -band (-bnot [System.IO.FileAttributes]::ReadOnly) | ||
$dirInfo.Delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested with changing two remove_
function's contents to Remove-Item
(after fix typo in L1216), and also with replacing all remove_junction
and remove_hardlink
with Remove-Item xxx -Recurse -Force | Out-Null
(with a file existing check in link_current
), and gotten no error. Maybe need more test.
PS. I've googled that without -Force
may return the error that not in interactive mode
. May help.
Can most values default, so "persist": [
{
"name": "config.dat" // type=file, method=link
},
{
"name": "data/" // type=directory, method=link
}
] works? |
Yes, it works, use a regex to judge if it contains "/" or "", as a shorcut of "type". |
No need to use regex. Just |
Remark for |
@h404bi Agree. I've tested with an admin account (with and without elevated privilege) and a non-admin test acount, and didn't gotten error with |
This is to prevent file overwriting instead of file editing? (mainly some qT apps ScoopInstaller/Extras#2018) If yes i would suggest this tweak to description: -Before update
+Before uninstallation |
Persist doesn't seem to work properly (see ScoopInstaller/Scoop#3212) for now, so doing it manually Co-Authored-By: Jakub Čábera <[email protected]> Co-Authored-By: linsui <[email protected]>
Reference discussions: #2897 #3209
Complete rework of the
persist
property including backward compatibility.persist
-objects to JSON Schema subject to changemethod
merge
: Merge new Languages/Plugins/Skins directory with current persistent directory to update those but don't lose changes made by the usercopy
: just copy directory or file (maybe the same asmerge
)link
: create hardlink for files or junctions for directoriesencoding
: file encoding (not used for directories)type
: eitherfile
ordirectory
content
: either string or array of stringsglue
: characters to joincontent
array (default\n
)$env:COMSPEC
andattrib
callspersist_data
behaviour topersist_data_old
subject to changeCases that need to be adressed:
content
and hardlink itlink
)link
)<name>.original
?merge
)<filename>.original
to keep changeslink
)<name>.original
?merge
)