Extras icon indicating copy to clipboard operation
Extras copied to clipboard

[email protected]: Persist data

Open Ra2-IFV opened this issue 8 months ago • 14 comments

  • [x] Use conventional PR title: <manifest-name[@version]|chore>: <general summary of the pull request>
  • [x] I have read the Contributing Guide

Ra2-IFV avatar Apr 20 '25 03:04 Ra2-IFV

All changes look good.

Wait for review from human collaborators.

gimp

  • [x] Description
  • [x] License
  • [x] Hashes
  • [x] Checkver
  • [x] Autoupdate
  • [x] Autoupdate Hash Extraction

github-actions[bot] avatar Apr 20 '25 03:04 github-actions[bot]

https://github.com/ScoopInstaller/Main/pull/6462#discussion_r2106079501

Lutra-Fs avatar May 25 '25 04:05 Lutra-Fs

I think it would be simpler to use the following directly without obtaining the relevant version information through a script:

{
    "env_set": {
        "GIMP3_DIRECTORY": "$dir\\3.0"
    }
}

SorYoshino avatar Sep 08 '25 18:09 SorYoshino

This prevents scoop from overwriting user's env.

Ra2-IFV avatar Sep 17 '25 09:09 Ra2-IFV

This prevents scoop from overwriting user's env.

Hello, if my understanding of "preventing scoop from overwriting the user's environment" aligns with yours, I don't believe your current script achieves this for the following reasons:

The script in post_install runs during every installation or update. Although you check whether $Env:GIMP3_DIRECTORY exists and only add it to the environment variables if it doesn't exist, However, the script in post_uninstall runs during every update, which removes $Env:GIMP3_DIRECTORY. Consequently, when you later execute the script in post_install, $Env:GIMP3_DIRECTORY no longer exists.

{
    "post_install": [
      "if ($global) { $scope = 'Machine' } else { $scope = 'User' }",
      "if (!$Env:GIMP3_DIRECTORY) { [Environment]::SetEnvironmentVariable('GIMP3_DIRECTORY', \"$persist_dir\\3.0\", $scope) }"
    ],
    "post_uninstall": [
      "if ($global) { $scope = 'Machine' } else { $scope = 'User' }",
      "if ($Env:GIMP3_DIRECTORY -eq \"$persist_dir\\3.0\") { [Environment]::SetEnvironmentVariable('GIMP3_DIRECTORY', [NullString]::Value, $scope) }"
    ]
}

This behavior is identical to that of the env_set script.

If you check $cmd -eq uninstall, $Env:GIMP3_DIRECTORY won't be overwritten. However, this also prevents $Env:GIMP3_DIRECTORY from being deleted during future updates when $Env:GIMP4_DIRECTORY is needed.

SorYoshino avatar Sep 17 '25 10:09 SorYoshino

Uh, I didn't get it... In uninstall script GIMP3_DIRECTORY is removed only when the value of GIMP3_DIRECTORY equals to scoop's persist path, if not, it skips. So confused... what you are talking about? Don't know $cmd -eq uninstall, very useful to me, thanks!

Ra2-IFV avatar Sep 19 '25 06:09 Ra2-IFV

I believe the following example illustrates my previous point.

# Modify the script within "post_uninstall"
┏[ D:\Temporary\Software\Microsoft\Windows Sandbox]
└─>  jq -r '"post_install:", (.post_install[]), "", "post_uninstall:", (.post_uninstall[])' .\Gimp.json
post_install:
if ($global) { $scope = 'Machine' } else { $scope = 'User' }
if (!$Env:GIMP3_DIRECTORY) { [Environment]::SetEnvironmentVariable('GIMP3_DIRECTORY', "$persist_dir\3.0", $scope) }

post_uninstall:
if ($global) { $scope = 'Machine' } else { $scope = 'User' }
Write-Host "INFO  `$Env:GIMP3_DIRECTORY = " -NoNewline
[Environment]::GetEnvironmentVariable('GIMP3_DIRECTORY')
$result = $Env:GIMP3_DIRECTORY -eq "$persist_dir\3.0"
Write-Host "INFO  result is $result"
if ($Env:GIMP3_DIRECTORY -eq "$persist_dir\3.0") {
    [Environment]::SetEnvironmentVariable('GIMP3_DIRECTORY', [NullString]::Value, $scope)
}

┏[ D:\Temporary\Software\Microsoft\Windows Sandbox]
└─[#]>  scoop install .\Gimp.json
Installing 'Gimp' (3.0.4) [64bit] from 'D:\Temporary\Software\Microsoft\Windows Sandbox\Gimp.json'
Loading gimp-3.0.4-setup.exe from cache.
Checking hash of gimp-3.0.4-setup.exe ... ok.
Extracting gimp-3.0.4-setup.exe ... done.
Running installer script...done.
Linking D:\Software\Scoop\Local\apps\Gimp\current => D:\Software\Scoop\Local\apps\Gimp\3.0.4
Creating shim for 'gimp-console-3.0'.
Creating shim for 'gimp-console'.
Creating shim for 'gimp'.
Creating shim for 'gimptool-3.0'.
Creating shim for 'gimptool'.
Creating shortcut for GIMP (gimp-3.0.exe)
Persisting _userdata
Running post_install script...done.
'Gimp' (3.0.4) was installed successfully!
Notes
-----
Scoop persists data since version 3.0.4. You may need to move data by yourself.
Before: '$Env:APPDATA\GIMP\3.0'
After : 'D:\Software\Scoop\Local\persist\Gimp\gimp\3.0'

# Open another PowerShell session
┏[ ~]
└─[#]>  scoop update Gimp -f
Gimp: 3.0.4 -> 3.0.4
Updating one outdated app:
Updating 'Gimp' (3.0.4 -> 3.0.4)
Downloading new version
Loading gimp-3.0.4-setup.exe from cache.
Checking hash of gimp-3.0.4-setup.exe ... ok.
Uninstalling 'Gimp' (3.0.4)
Removing shim 'gimp-console-3.0.shim'.
Removing shim 'gimp-console-3.0.exe'.
Removing shim 'gimp-console.shim'.
Removing shim 'gimp-console.exe'.
Removing shim 'gimp.shim'.
Removing shim 'gimp.exe'.
Removing shim 'gimptool-3.0.shim'.
Removing shim 'gimptool-3.0.exe'.
Removing shim 'gimptool.shim'.
Removing shim 'gimptool.exe'.
Unlinking D:\Software\Scoop\Local\apps\Gimp\current
Running post_uninstall script...INFO  $Env:GIMP3_DIRECTORY = D:\Software\Scoop\Local\persist\Gimp\3.0
INFO  result is True
done.
Installing 'Gimp' (3.0.4) [64bit] from 'D:\Temporary\Software\Microsoft\Windows Sandbox\Gimp.json'
Loading gimp-3.0.4-setup.exe from cache.
Extracting gimp-3.0.4-setup.exe ... done.
Running installer script...done.
Linking D:\Software\Scoop\Local\apps\Gimp\current => D:\Software\Scoop\Local\apps\Gimp\3.0.4
Creating shim for 'gimp-console-3.0'.
Creating shim for 'gimp-console'.
Creating shim for 'gimp'.
Creating shim for 'gimptool-3.0'.
Creating shim for 'gimptool'.
Creating shortcut for GIMP (gimp-3.0.exe)
Persisting _userdata
Running post_install script...done.
'Gimp' (3.0.4) was installed successfully!
Notes
-----
Scoop persists data since version 3.0.4. You may need to move data by yourself.
Before: '$Env:APPDATA\GIMP\3.0'
After : 'D:\Software\Scoop\Local\persist\Gimp\gimp\3.0'

$Env:GIMP3_DIRECTORY -eq \"$persist_dir\\3.0\ always evaluates to true.

SorYoshino avatar Sep 19 '25 11:09 SorYoshino

No way...

bash-5.2 $ echo $GIMP3_DIRECTORY
C:\ProgramData\scoop\persist\gimp1
bash-5.2 $ scoop uninstall -g gimp
Uninstalling 'gimp' (3.0.4).
Removing shim 'gimp-console-3.0.shim'.
Removing shim 'gimp-console-3.0.exe'.
Removing shim 'gimp-console.shim'.
Removing shim 'gimp-console.exe'.
Removing shim 'gimp.shim'.
Removing shim 'gimp.exe'.
Removing shim 'gimptool-3.0.shim'.
Removing shim 'gimptool-3.0.exe'.
Removing shim 'gimptool.shim'.
Removing shim 'gimptool.exe'.
Removing shortcut C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Scoop Apps\GIMP.lnk
Unlinking C:\ProgramData\scoop\apps\gimp\current
'gimp' was uninstalled.
bash-5.2 $ scoop cat gimp
{
    "##": "Maintainer reminder: After major releases, update version number in notes, and variable in post install/uninstall scripts",
    "version": "3.0.4",
    "description": "GNU Image Manipulation Program",
    "homepage": "https://www.gimp.org",
    "license": "GPL-3.0-only",
    "url": "https://download.gimp.org/mirror/pub/gimp/v3.0/windows/gimp-3.0.4-setup.exe",
    "hash": "385e36fe577cbdbfc71ba79d6c046d6f4eaabc01effd7f067bf15fd98410b2a1",
    "notes": [
        "Scoop persists data since version 3.0.4. You may need to move data by yourself.",
        "Before: '$Env:APPDATA\\GIMP\\3.0'",
        "After : '$persist_dir\\gimp\\3.0'"
    ],
    "innosetup": true,
    "installer": {
        "script": [
            "$scriptver = $version -split '[-.]'",
            "$shortver = $scriptver[0] + '.' + $scriptver[1]",
            "Push-Location \"$dir\"",
            "Get-ChildItem -Filter '*.debug' -Recurse | Remove-Item -Recurse",
            "$file64 = Get-ChildItem -Recurse -Filter '*,?.*' | Where-Object {",
            "   $_.Name -match '^(.*?),[12]\\.(.*?)$' -and",
            "   (-not (Test-Path (Join-Path $_.Directory.FullName \"$($matches[1]),3.$($matches[2])\"))) -and",
            "   $matches[1] -ne 'libhwy'",
            "}",
            "$file64 | Rename-Item -NewName { $_.name -Replace ',2', ',3' }",
            "$file64 | Rename-Item -NewName { $_.name -Replace ',1', ',2' }",
            "if ($architecture -eq '32bit') {",
            "   Get-ChildItem -Filter '*,1*' -Recurse | Rename-Item -NewName { $_.name -Replace ',1', '' }",
            "} else {",
            "   # 'twain.exe' is for 'gimp32on64' which is not included.",
            "   Remove-Item \"lib\\gimp\\$shortver\\plug-ins\\twain\" -Recurse -Force",
            "   if ($architecture -eq '64bit') {",
            "       Get-ChildItem -Filter '*,2*' -Recurse | Rename-Item -NewName { $_.name -Replace ',2', '' }",
            "   } else {",
            "       Get-ChildItem -Filter '*,3*' -Recurse | Rename-Item -NewName { $_.name -Replace ',3', '' }",
            "   }",
            "}",
            "Get-ChildItem -Filter '*,*' -Recurse | Remove-Item",
            "Pop-Location"
        ]
    },
    "post_install": [
        "if ($global) { $scope = 'Machine' } else { $scope = 'User' }",
        "if (!$Env:GIMP3_DIRECTORY) { [Environment]::SetEnvironmentVariable('GIMP3_DIRECTORY', \"$persist_dir\\3.0\", $scope) }"
    ],
    "bin": [
        "bin\\gimp-console-3.0.exe",
        [
            "bin\\gimp-console-3.0.exe",
            "gimp-console"
        ],
        [
            "bin\\gimp-console-3.0.exe",
            "gimp"
        ],
        "bin\\gimptool-3.0.exe",
        [
            "bin\\gimptool-3.0.exe",
            "gimptool"
        ]
    ],
    "shortcuts": [
        [
            "bin\\gimp-3.0.exe",
            "GIMP"
        ]
    ],
    "persist": [
        [
            "_userdata",
            "3.0"
        ]
    ],
    "post_uninstall": [
        "if ($global) { $scope = 'Machine' } else { $scope = 'User' }",
        "if ($Env:GIMP3_DIRECTORY -eq \"$persist_dir\\3.0\") { [Environment]::SetEnvironmentVariable('GIMP3_DIRECTORY', [NullString]::Value, $scope) }"
    ],
    "checkver": {
        "url": "https://www.gimp.org/downloads/",
        "regex": "gimp-(?[\\d.]+)-setup(?-\\d)?\\.exe",
        "replace": "${version}${build}"
    },
    "autoupdate": {
        "url": "https://download.gimp.org/mirror/pub/gimp/v$majorVersion.$minorVersion/windows/gimp-$matchHead-setup$matchTail.exe",
        "hash": {
            "url": "$baseurl/SHA256SUMS"
        },
        "bin": [
            "bin\\gimp-console-$majorVersion.$minorVersion.exe",
            [
                "bin\\gimp-console-$majorVersion.$minorVersion.exe",
                "gimp-console"
            ],
            [
                "bin\\gimp-console-$majorVersion.$minorVersion.exe",
                "gimp"
            ],
            "bin\\gimptool-$majorVersion.$minorVersion.exe",
            [
                "bin\\gimptool-$majorVersion.$minorVersion.exe",
                "gimptool"
            ]
        ],
        "shortcuts": [
            [
                "bin\\gimp-$majorVersion.$minorVersion.exe",
                "GIMP"
            ]
        ]
    }
}
  

Ra2-IFV avatar Oct 07 '25 19:10 Ra2-IFV

Thank you for your explanation. I think I understand your point now. You are considering the scenario where this environment variable already exists during installation, while I am considering a fresh installation or a situation where the environment variable does not exist.

However, I still believe this approach is problematic for the following reasons:

  1. If this manifest is used to install or upgrade Gimp when the environment variable does exist, it can indeed prevent the user-defined variable from being overwritten. However, due to the presence of this variable, related data might be stored outside the $persist_dir directory. In that case, the notes and persist fields in the manifest would lose their purpose and could even become contradictory.
  2. When the environment variable does not exist, the behavior of the relevant code inside the manifest becomes identical to using env_set. In this situation, the contents of the post_install and post_uninstall sections would become meaningless.

In addition, I have concerns about the persist field in the manifest:

  1. It does not follow the expected format and should be written in the same way as the shortcuts field.

  2. You chose to store related data in $persist_dir\3.0. I assume the main reason is that you want to separate user data for different major versions. Moreover, you added a ## comment to remind future maintainers to update the version number in the notes, post_install, and post_uninstall fields.

    • However, this approach undoubtedly increases the maintenance burden for the community. If no one updates the manifest in the future, continuing to use $persist_dir\3.0 when the version reaches 4.x will definitely cause problems.

    • The content of the ## comment is also unclear — in fact, the version number in the persist field must also be updated. Otherwise, it could lead to data loss or other related issues.


Please note that the above opinions are solely my personal views. I am not a maintainer, nor do I intend to impose any requirement for you to modify the manifest based on my suggestions.

SorYoshino avatar Oct 08 '25 15:10 SorYoshino