This is temporary solution for #2220 until whole install.ps1 refactor is done to make this tweak easily, in the best way one-liner.
- One step closer to #3149
- Closes#2220
- Closes#2343
- Closes#1605
* buckets: Move function into lib from lib-exec
There is no reason to have it inside lib-exec since, it's all internal functions, which could be used inside other code
lib-exec scripts should be slimmed as possible, as they are only code runners with some validation
* Fix whitespace
**Data matters, please review**
This is a rework of #2891#2890 and #2882 . This will also fix#2724 and fix#2900 , close#2779
**Introduction**
I add a function called `unlink_persist_data($dir)`, which recursively unlink all junction/hard link in the given directory. This affects some sub-commands which have interaction with junction/hard link:
- `scoop-install`: the persisting logic has been improved as follow:
1. if there are data in the `persist` folder, also in app(`source`) folder, rename that one located in app folder (e.g. app's default setting files) with a `original` suffix, then create link from `persist` to app
2. if there are data in the `persist` folder, but no in app(`source`) folder, just create link from `persist` to app
3. if there is no data in the `persist` folder (e.g. fresh install), but there are data in app(`source`) folder (e.g. app's default setting files), we will just use that default setting files as the first-time persisting. So move that files from app folder to `persist` folder, then create link from `persist` to app
4. But what if if there is neither data in the `persist` folder (e.g. fresh install), nor in the app(`source`) folder (e.g. setting files will be created after first startup, like `Everthing.db`). We need to create empty persisting target in the `persist` folder. But by default we can't know if a persisting target is a file or a directory (e.g. `conf.d`). So we create a directory by default, and to avoid this, manifest maintainers should use `pre_install` to manually create the source file before persisting.
- `scoop-reset`: `reset` command uses the logic of `install`, but there is a problem: before re-persisting data, there have been `junction/hard link` in the app(`source`) folder. It will throw an exception of file exists #2724 . To fix this, we should unlink all old link before re-persisting, using `unlink_persist_data`.
- `scoop-uninstall`: `Remove-Item` can not remove `NTFS junction`, we need to unlink all persistting data, before uninstalling/deleting an app, but keeping persisting data.
- `scoop-cleanup`: like `uninstall`, `Remove-Item` can not remove `NTFS junction`, we need to unlink all persistting data, before deleting old versions of an app. Before PR #2882 , it use `fsutil.exe` to unlink junction, which is not friendly to restricted users (#2832 and #2881 ).
Beyond the logic improvement, there is a new feature now: it supports sub-folder data persisting, like:
```json
{
"homepage": "https://scoop.sh",
"description": "A dummy manifest for scoop tests.",
"license": "Freeware",
"version": "1.1.0",
"url": "https://get.scoop.sh",
"pre_install": [
"if (!(test-path \"$dir\\dummy.txt\")) { new-item -force \"$dir\\dummy.txt\" -itemtype file | out-null }",
"if (!(test-path \"$dir\\dummydir\")) { new-item \"$dir\\dummydir\" -itemtype directory | out-null }",
"if (!(test-path \"$dir\\subdir\")) { new-item \"$dir\\subdir\" -itemtype directory | out-null }",
"if (!(test-path \"$dir\\subdir\\subdummydir\")) { new-item \"$dir\\subdir\\subdummydir\" -itemtype directory | out-null }",
"if (!(test-path \"$dir\\subdir\\subdummy.txt\")) { new-item -force \"$dir\\subdir\\subdummy.txt\" -itemtype file | out-null }",
],
"persist": [
"dummy.txt",
"dummydir",
"subdir\\subdummydir",
"subdir\\subdummy.txt"
]
}
```
So no need to strip directories of source for target anymore.
To participate in the code review and tests, go visit https://github.com/h404bi/scoop-persist-test for test cases.
* scoop-cleanup: handle with junction better
* scoop-cleanup: only resolve directory symbolic link
* scoop-cleanup: stop removing when an error occurs.
* Add show_app() function for displaying `app/bucket@version`
* Add option to skip hash check on install/update
Allows users to install an app when the manifest provides an outdated hash
* Show filename instead of robocopy output when moving fails
* Add new_issue_msg() for nicer error messages (with link bucket repo)
- returns a message with a link to the buckets GitHub repository
- clicking on the link opens a new issues with a predefined title
* Use new_issue_msg() for errors while moving files
- this removes the unreadable robocopy error dumps
* Use new_issue_msg() error handling for check_hash()
* Show robocopy exit code
Shows information about an installed app.
- name and description
- version and latest version
- license (with link to spdx.org)
- linked binaries
- shows install notes
- URL or path to manifest
* Fix interpretation of response's status code to detect redirections
* Improve documentation of virustotal subcommand
- usage & configuration of virustotal_api_key
- special parameter '*' to test all installed apps
- make necessity of having a virustotal_api_key for --scan explicit
- show that it's possible to check several packages at once
* Never use virustotal_api_key to query if a package is safe
The URL in the code wasn't an API end-point anyway.
* Refactor logic to warn user about apps unknown to VirusTotal
* Warn once when virustotal_api_key's absence prevents VirusTotal submission
This is preparation for changes to come in the package submission logic.
* Use API to submit download link to VirusTotal, rate limited in EAFP fashion
This is a roundabout way to get the file to be scanned without having
to download & upload it ourselves.
Rate limiting is implemented using EAFP: if submission fails, we wait
at least 60s before retrying at most once.
* Color undecided VirusTotal information the same way as `dangerous' files
If the scanning is still in progress, VirusTotal returns 0 malicious,
0 suspicious and 0 undetected. Err on the safe side and color this
the same way as `dangerous' files.
* Remove requirement to only verify installed apps
The initial use case for this feature was to scan packages to avoid
installing dangerous apps. Assuming they are infected, we want if
possible to avoid downloading them at all.
* Check dependencies with VirusTotal, too (by default)
* Manually apply `Lint: PSAvoidUsingCmdletAliases' (see e1bb1e91, #2075)
This is to avoid conflicts when merging lukesampson:master
* Explain applist's return value transformation: drop `global' flag for each app
* Move variable declarations and apps list generation to the top
* Reformat code and comply to linted function names
* Reduce nesting, remove hacky hash/url retrieval
* Remove $global variables
* Fix regression bug in Search-VirusTotal()
* Remove applist() because it's irrelevant if app is installed globally
Removes extra 'ERROR' in text where the `error` method is used.
Converts some `write-host "error message"` to use the `error` method
Converts some `write-host "error message"; exit 1` to use the `abort`
method.