Skip to content
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

Trashbin skip list #38704

Merged
merged 1 commit into from
May 18, 2021
Merged

Trashbin skip list #38704

merged 1 commit into from
May 18, 2021

Conversation

AlexAndBear
Copy link

@AlexAndBear AlexAndBear commented May 6, 2021

Description

With this change new config parameters has been introduced.
Admins can now decide, based on file extensions, directory names and size,
if a resource should not be observed by the trashbin and deleted immediately.

Motivation and Context

How Has This Been Tested?

  • test environment:
  • test case 1:
  • test case 2:
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@AlexAndBear
Copy link
Author

originated from https://github.com/owncloud/files_backup/pull/39

@jvillafanez
Copy link
Member

Just a couple of things so far:

  • I'd move the checks to its own class. This way it's easier to add unit tests for this and it also keeps the code isolated.
  • I'd try to avoid using regular expressions unless needed.
    • So far, the examples provided in the config.php are for extensions and files inside folders (basically, paths ending or starting with some chars). This can be done faster without regular expressions.
    • Regular expressions are error-prone. My concern here is that the admin could enter a "wrong" regular expression, such as .*.png which could affect to files the admin doesn't want to, such as a_file.apng. This simply cannot be detected.
    • Case insensitiveness seems a bad idea if it wasn't asked for explicitly. The config.php file doesn't say anything about this.
  • Taking into account that we don't expect too many skips, we probably should include some logs at info level (warning might be too much) for tracing purposes.

@AlexAndBear
Copy link
Author

@jvillafanez what do you think about the current solution?

@AlexAndBear AlexAndBear changed the title Trashbin skip list regex Trashbin skip list May 11, 2021
@owncloud owncloud deleted a comment from update-docs bot May 11, 2021
@AlexAndBear AlexAndBear marked this pull request as ready for review May 11, 2021 13:44
@jvillafanez
Copy link
Member

I still think it's better to move the checks to a dedicated class. We'll need to add unit tests, and it should be easy to add them in a dedicated class. It should also be easier to include an initialization phase to clean the config input and make the actual action easier to read.
In addition, it might be better to split into multiple smaller functions in order to give meaningful names to the functions to make the code easier to follow.

Also note that there could be filenames with "*" in the path (I don't think we're doing anything special), so there could be a "*abc" folder in the root.

@AlexAndBear
Copy link
Author

@jvillafanez No Thing, we can move it

@jvillafanez
Copy link
Member

Note that we should include an option to skip the trashbin by filesize, which will probably be the main use case for this feature. Taking this into account, maybe having "trashbin.skip.extensions", "trashbin.skip.directories" and "trashbin.skip.sizes" as config options might be a better choice

@jvillafanez
Copy link
Member

I think so. The code seems complex at first sight, probably because the PHP string functions aren't easy to handle, and it also has some edge cases we need to take care. I don't mind having the wildcard logic if it easy to follow though.
My concern is that a 3rd person might take 1-2 days trying to put a fix there successfully because every time he touches something he breaks another thing. If you're confident your code is fool-proof, go ahead.

@AlexAndBear
Copy link
Author

@jvillafanez can you have a second look, this is not quite final, tests need to be added.

.htaccess Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/SkipTrashbinManager.php Outdated Show resolved Hide resolved
apps/files_trashbin/lib/Storage.php Outdated Show resolved Hide resolved
config/config.sample.php Outdated Show resolved Hide resolved
@jvillafanez
Copy link
Member

For the config.sample file, I prefer to use the default values if any. If it isn't possible (the defaults in this case will likely be empty lists, which doesn't add any value), some sane defaults is a better choice, so it's easy to copy and paste them. You might also want to clarify whether there is a default value in use or not (mainly to clarify that 1GB files will still reach the trashbin by default, for example). You can add additional examples in the comments to clarify things.
In this regard, you could include:

  • for the extensions, the .exe files or .mkv might be more common choices.
  • for the directories, I think our use case is the .snapshot folder. It's something we might need, so better to have it around
  • for the filesize, 1GB seems reasonable. Depending on the usage, you might want to increase it to 5GB or 10GB

@JammingBen
Copy link
Contributor

@jvillafanez I updated the PR with some general improvements and your suggestions. Also added tests for the new class. I'm not a 100% sure about the ´config.sample´ yet. At least it should now be more clear how to use these config params.

Thanks for your help here btw 👍

@jvillafanez
Copy link
Member

Warning messages seem harsh. I understand that we might want that message for the "skip directories" configuration as a deterrent, but the ones for the extension and file size... I expect the skip by file size to be widely used.

@AlexAndBear
Copy link
Author

AlexAndBear commented May 14, 2021

TBD:

  • Inform @mmattel to run config-to-docs-command for 10.8

@mmattel
Copy link
Contributor

mmattel commented May 14, 2021

@janackermann @jvillafanez
Could you pls make in config.php each first line a brief description line as you can see in the other examples above or below.
The first line of a new config parameter is always taken as line for the table of contents. The lines below can be anything you like. See also the doc on the web how it renders.
I would like to avoid post merge corrections if possible 😃

@AlexAndBear AlexAndBear requested a review from mmattel May 14, 2021 15:34
config/config.sample.php Outdated Show resolved Hide resolved
config/config.sample.php Outdated Show resolved Hide resolved
config/config.sample.php Outdated Show resolved Hide resolved
config/config.sample.php Outdated Show resolved Hide resolved
@jvillafanez
Copy link
Member

I think those will be the last changes for me.

config/config.sample.php Outdated Show resolved Hide resolved
config/config.sample.php Outdated Show resolved Hide resolved
config/config.sample.php Outdated Show resolved Hide resolved
@mmattel
Copy link
Contributor

mmattel commented May 17, 2021

For some strange reasons, already committed text suggestions for config.php got corrupted.
For one smaller corruption, I changed the bad line and committed it directly.
The other reconstructed suggestion is multi line and I would like to get another eye on @janackermann

EDIT: fixed

@AlexAndBear AlexAndBear force-pushed the trashbin-skip-list-regex branch 2 times, most recently from 04592bd to 6a18869 Compare May 17, 2021 12:52
@AlexAndBear AlexAndBear requested a review from mmattel May 17, 2021 13:07
@AlexAndBear AlexAndBear force-pushed the trashbin-skip-list-regex branch 2 times, most recently from aa58dce to 5154722 Compare May 17, 2021 13:41
@mmattel
Copy link
Contributor

mmattel commented May 17, 2021

@jvillafanez

the .htaccess file shouldn't be modified.

This has been fixed by @janackermann, no changes in the file.
Pls re-review/approve.

Copy link
Contributor

@mmattel mmattel left a comment

Choose a reason for hiding this comment

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

OK from the config.php POV
Code not tested

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

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

Tiny detail, maybe for the next time.

apps/files_trashbin/lib/TrashbinSkipChecker.php Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented May 18, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

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.

5 participants