8000 refactor(persist): Allow explicit declaration of persistent item types by HUMORCE · Pull Request #6367 · ScoopInstaller/Scoop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor(persist): Allow explicit declaration of persistent item types #6367

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

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

HUMORCE
Copy link
Member
@HUMORCE HUMORCE commented May 22, 2025

Description

Motivation and Context

Closes #6179

before:
will create empty dir for non-existent items

"persist": "app.conf"
"persist": [ "app.conf", "conf" ]
"persist": [ ["app.conf", "app.json"], ["conf", "config"] ]

after:
will create empty file/dir for non-existent items by its property

<All legacy behavior> # will create empty dir for non-existent items

"persist": { "file": <ALL_BEFORE_FORMAT>, "directory": <ALL_BEFORE_FORMAT> }
"persist": { "file": <ALL_BEFORE_FORMAT>, "directory": <ALL_BEFORE_FORMAT> }
"persist": { "file": <ALL_BEFORE_FORMAT>, "directory": <ALL_BEFORE_FORMAT> }

example: (obs-studio)
    "pre_install": "if (!(Test-Path \"$persist_dir\\portable_mode.txt\")) { New-Item \"$dir\\portable_mode.txt\" | Out-Null }",
    # delete pre_install
    "persist": {
        "file": "portable_mode.txt",
        "directory": [
            "config",
            "obs-plugins"
        ]
    },

How Has This Been Tested?

persistence.json

❯ scoop install persistence -u
Installing 'persistence' (0.9.7) [64bit] from 'tests' bucket
Loading zoxide-0.9.7-x86_64-pc-windows-msvc.zip from cache
Checking hash of zoxide-0.9.7-x86_64-pc-windows-msvc.zip ... ok.
Extracting zoxide-0.9.7-x86_64-pc-windows-msvc.zip ... done.
Linking ~\scoop\apps\persistence\current => ~\scoop\apps\persistence\0.9.7
Persisting file 'README.md'
Persisting file 'conf\config.toml'
Persisting file 'conf.d\user\config.toml'
Persisting file 'LICENSE'
Persisting file '0.9.7'
Persisting directory 'man'
Persisting directory 'completions'
'persistence' (0.9.7) was installed successfully!
~
❯ ls (scoop prefix persistence)

    Directory: C:\Users\humorce\scoop\apps\persistence\current

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
l-r--           5/22/2025  7:11 AM                completions -> C:\Users\humorce\scoop\persist\persistence\completion
d----           5/22/2025  7:11 AM                conf
d----           5/22/2025  7:11 AM                conf.d
l-r--           5/22/2025  7:11 AM                man -> C:\Users\humorce\scoop\persist\persistence\man
-a---           5/22/2025  7:11 AM              0 0.9.7
-a---            2/9/2025  9:47 PM          15537 CHANGELOG.md
-a---           5/22/2025  7:11 AM             59 install.json
-a---            2/9/2025  9:47 PM           1060 LICENSE
-a---           5/22/2025  6:49 AM           1771 manifest.json
-a---            2/9/2025  9:47 PM          25453 README.md
-a---            2/9/2025  9:49 PM        1268224 zoxide.exe

~
❯ (Get-Item "$(scoop prefix persistence)\conf\config.toml").LinkType
HardLink
~
❯ scoop uninstall persistence
Uninstalling 'persistence' (0.9.7).
Unlinking ~\scoop\apps\persistence\current
'persistence' was uninstalled.
~
❯ scoop install persistence -u
Installing 'persistence' (0.9.7) [64bit] from 'tests' bucket
Loading zoxide-0.9.7-x86_64-pc-windows-msvc.zip from cache
Checking hash of zoxide-0.9.7-x86_64-pc-windows-msvc.zip ... ok.
Extracting zoxide-0.9.7-x86_64-pc-windows-msvc.zip ... done.
Linking ~\scoop\apps\persistence\current => ~\scoop\apps\persistence\0.9.7
Persisting file 'README.md'
Persisting file 'conf\config.toml'
Persisting file 'conf.d\user\config.toml'
Persisting file 'LICENSE'
Persisting file '0.9.7'
Persisting directory 'man'
Persisting directory 'completions'
'persistence' (0.9.7) was installed successfully!
~
❯ scoop uninstall persistence -p
Uninstalling 'persistence' (0.9.7).
Unlinking ~\scoop\apps\persistence\current
Removing persisted data.
'persistence' was uninstalled.

legacy persistence:

wakemeonlan: Same behavior as before, it still a wrong persistence, because it's wrong when written.

❯ scoop install wakemeonlan -u
Installing 'wakemeonlan' (1.93) [64bit] from 'nirsoft' bucket
Loading wakemeonlan-x64.zip from cache
Checking hash of wakemeonlan-x64.zip ... ok.
Extracting wakemeonlan-x64.zip ... done.
Linking ~\scoop\apps\wakemeonlan\current => ~\scoop\apps\wakemeonlan\1.93
Creating shim for 'WakeMeOnLan'.
Making C:\Users\humorce\scoop\shims\wakemeonlan.exe a GUI binary.
Creating shortcut for NirSoft\WakeMeOnLan (WakeMeOnLan.exe)
Persisting directory 'wakemeonlan_lng.ini'
Persisting directory 'wakemeonlan.cfg'
'wakemeonlan' (1.93) was installed successfully!
Notes
-----
If this application is useful to you, please consider donating to NirSoft - https://www.nirsoft.net/donate.html
~
❯ ls (scoop prefix wakemeonlan)

    Directory: C:\Users\humorce\scoop\apps\wakemeonlan\current

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
l-r--           5/22/2025  7:15 AM                wakemeonlan_lng.ini ->
                                                  C:\Users\humorce\scoop\persist\wakemeonlan\wakemeonlan_lng.ini
l-r--           5/22/2025  7:15 AM                wakemeonlan.cfg -> C:\Users\humorce\scoop\persist\wakemeonlan\wakemeonlan.cfg
-a---           5/22/2025  7:15 AM             61 install.json
-a---           3/18/2025 10:54 AM           1401 manifest.json
-a---           3/13/2025  1:52 PM          21078 readme.txt
-a---           3/13/2025  1:52 PM          19974 WakeMeOnLan.chm
-a---           3/13/2025  1:50 PM        1324032 WakeMeOnLan.exe

rufus: Same behavior as before

❯ scoop install rufus -u
Installing 'rufus' (4.7) [64bit] from 'extras' bucket
Loading rufus-4.7.exe from cache
Checking hash of rufus-4.7.exe ... ok.
Running pre_install script...done.
Linking ~\scoop\apps\rufus\current => ~\scoop\apps\rufus\4.7
Creating shim for 'rufus'.
Making C:\Users\humorce\scoop\shims\rufus.exe a GUI binary.
Creating shortcut for Rufus (rufus.exe)
Persisting directory 'rufus.ini'
Persisting directory 'rufus_files'
'rufus' (4.7) was installed successfully!
~
❯ ls (scoop prefix rufus)

    Directory: C:\Users\humorce\scoop\apps\rufus\current

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
l-r--           5/22/2025  7:18 AM                rufus_files -> C:\Users\humorce\scoop\persist\rufus\rufus_files
-a---           5/22/2025  7:18 AM             60 install.json
-a---            4/9/2025  7:45 PM           1833 manifest.json
-a---           5/22/2025  7:18 AM        1687344 rufus.exe
-a---           3/18/2025 11:10 AM            130 rufus.ini

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly. (TODO: when merged)
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@HUMORCE HUMORCE requested a review from Copilot May 22, 2025 08:20
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the “persist” manifest entry to allow an explicit object form with separate file and directory lists, while preserving legacy array/schema support.

  • Adds a new persist definition in schema.json that accepts either the legacy string/array formats or an object with file and/or directory keys.
  • Refactors persist_data and unlink_persist_data in lib/install.ps1 to 8000 build and process separate lists for files vs. directories based on the new schema.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
schema.json Replaces legacy refs with a new persist definition allowing explicit file/directory object
lib/install.ps1 Updates persist_data and unlink_persist_data to distinguish and handle file vs. directory entries
Comments suppressed due to low confidence (2)

lib/install.ps1:450

  • [nitpick] The variable name $persistence is easily confused with the input $persist. Consider renaming to something like $parsedPersist or $persistItems for clarity.
$persistence = [PSCustomObject]@{

lib/install.ps1:447

  • We should add unit or integration tests covering the new object-style persist (file vs directory) to ensure both legacy and new formats behave as expected.
function persist_data($manifest, $original_dir, $persist_dir) {

@@ -404,6 +404,37 @@
}
]
},
"persist": {
Copy link
Preview
Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new object form for persist should be documented in the manifest reference (README or docs) so users know the file/directory keys are now supported.

Suggested change
"persist": {
"persist": {
"description": "Specifies files or directories to persist across updates. Can be a string, an array of strings, or an object with 'file' and/or 'directory' keys. The 'file' key is used to specify files to persist, and the 'directory' key is used to specify directories to persist. At least one of 'file' or 'directory' must be provided.",

Copilot uses AI. Check for mistakes.

638700f < 8000 /div>
@HUMORCE HUMORCE changed the title refactor(persist): Allow explicit declaration for the type of persistent item refactor(persist): Allow explicit declaration of persistent file types May 22, 2025
@HUMORCE HUMORCE changed the title refactor(persist): Allow explicit declaration of persistent file types refactor(persist): Allow explicit declaration of persistent item types May 22, 2025
@@ -1,3 +1,9 @@
## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since v0.5.3 has not been released yet, I think the log entry should be added under v0.5.3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be change when #6257 include this PR.

Copy link
Member
@Lutra-Fs Lutra-Fs May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like 0.5.3's publish process is currently frozen >︿<

@niheaven
Copy link
Member
niheaven commented Jun 3, 2025

The persist refactor is here: #3248

Please wait while v0.5.3 is merged.

@HUMORCE
Copy link
Member Author
HUMORCE commented Jun 3, 2025

If you plan to continue implementing #3248, then I suggest you move 'type' to top-level like this PR to avoid redundantly type definitions, and have a strictly restrict for type-specific 'methods'. #6369 (comment)

@niheaven
Copy link
Member
niheaven commented Jun 3, 2025

I will proceed with a force merge of v0.5.3 if there are no further comments, and we can focus on adding more features afterward.

@BoringBoredom
Copy link

If you plan to continue implementing #3248, then I suggest you move 'type' to top-level like this PR to avoid redundantly type definitions, and have a strictly restrict for type-specific 'methods'. #6369 (comment)

I agree. #6369 (comment) is the more elegant solution, imo.

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

Successfully merging this pull request may close these issues.

4 participants
0