nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.49k stars 4.08k forks source link

fix(files): files:scan error ouput when user_id is not found + return correct exit status on error #49412

Open joshtrichards opened 1 day ago

joshtrichards commented 1 day ago

Summary

Note: This looks like a lengthier change than it really is due to moving the location of execute() for readability.

TODO

Notes

There are two behavior changes here to be aware of (in order order of probably significance in terms of being classified as a "breaking change"):

Exit code

Previously even where there were errors the exit code (i.e. echo $?) was still 0. Now any errors mean the code will be 1.

Output is slightly different when user_id is not found (e.g. see #27031 for existing behavior):

Now it is:

www-data@83e3407f887c:~/html$ ./occ files:scan -p "/a"
User 1 out of 1 not found (a)
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 0       | 0     | 0   | 0       | 0       | 1      | 00:00:00     |
+---------+-------+-----+---------+---------+--------+--------------+

Output

Output of occ files with this PR:

Available commands for the "files" namespace:
[...]  
  files:repair-tree                Try and repair malformed filesystem tree structures
  files:scan                       Scans the filesystem for new files and updates the file cache
  files:scan-app-data              rescan the AppData folder
[...]

Output of occ files:scan --help with this PR:

Description:
  Scans the filesystem for new files and updates the file cache

Usage:
  files:scan [options] [--] [<user_id>...]

Arguments:
  user_id                                      Rescan all files of the specified user(s)

Options:
      --output[=OUTPUT]                        Output format (plain, json or json_pretty, default is plain) [default: "plain"]
  -p, --path=PATH                              Limit rescan to the specified path, eg. --path="/alice/files/Music". Overrides the user_id and --all parameters.
      --generate-metadata[=GENERATE-METADATA]  Generate metadata for all scanned files; if specified only generate for named value. [default: ""]
      --all                                    Rescan all files of all known users
      --unscanned                              Only scan files which are marked as not fully scanned
      --shallow                                Do not scan folders recursively
      --home-only                              Only scan the home storage, ignoring any mounted external storage or share
  -h, --help                                   Display help for the given command. When no command is given display help for the list command
  -q, --quiet                                  Do not output any message
  -V, --version                                Display this application version
      --ansi|--no-ansi                         Force (or disable --no-ansi) ANSI output
  -n, --no-interaction                         Do not ask any interactive question
      --no-warnings                            Skip global warnings, show command output only
  -v|vv|vvv, --verbose                         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  You can rescan all files or only those of select user(s) or a select path. Statistics will be shown at the end of the scan by default.

Checklist