Skip to content

Remove empty directories from the files_versions #40499

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

Merged
merged 3 commits into from
Feb 13, 2023

Conversation

jvillafanez
Copy link
Member

Description

Empty directories were left inside the files_versions directory. For large installations this is a waste of space because there could be a lot of empty directories that aren't useful in any way.

Related Issue

https://github.com/owncloud/enterprise/issues/5471

Motivation and Context

How Has This Been Tested?

Mostly tested by deleting files from the web UI

  1. Create "/f1/f2/f3" folder and upload a file with some versions
  2. Check that the there are versions in <userdir>/files_versions/f1/f2/f3/
  3. Remove the uploaded file

There should be only the <userdir>/files_versions folder without any directory in it. This is because the "f1/f2/f3" folders were empty.

Additional checks done:

  • With multiple files, removing only one will keep the folder in the files_versions because there are more versions inside
  • Removing the directory containing the files (removing "/f1/f2/f3" folder so "/f1/f2" is empty). Only <userdir>/files_versions exists because the rest of the folders were empty.
  • Moving the files / directory around. As long as the source parent folder doesn't have versions, the folders will also be removed.
  • occ versions:cleanup and occ versions:expire works with the same conditions.

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

Note:
Existing empty version folder won't be removed unless a version ends up inside any of them. In this case, there won't be any difference and the folder will be removed once the last version is removed from the folder.

@jvillafanez jvillafanez self-assigned this Nov 16, 2022
@jvillafanez jvillafanez force-pushed the remove_empty_directory_versions branch from 4d7ad3e to 18842fb Compare November 16, 2022 16:11
@pako81
Copy link

pako81 commented Dec 6, 2022

Should we move this forward?

@jvillafanez
Copy link
Member Author

As far as I know, this just needs review and merge. The failing test is due to the missing windows server.

@pako81 pako81 requested review from mrow4a, IljaN and phil-davis December 7, 2022 15:37
@phil-davis phil-davis force-pushed the remove_empty_directory_versions branch from 2ac77af to ecfa0f8 Compare January 5, 2023 06:56
@owncloud owncloud deleted a comment from update-docs bot Jan 5, 2023
Copy link
Member

@DeepDiver1975 DeepDiver1975 left a comment

Choose a reason for hiding this comment

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

Any chance to add some tests to ensure that:

  • empty folders are deleted
  • non-empty folders are not deleted

THX

@phil-davis
Copy link
Contributor

Any chance to add some tests

Not sure if you mean unit tests or acceptance tests. The behavior to test is in the back-end implementation, so not directly visible to any API call. But we do have the testing app, and that has https://github.com/owncloud/testing/blob/master/lib/ServerFiles.php which allows access to "see" what files and directories exist in the back-end data storage.

So, I can add some acceptance tests that check the back-end storage behavior of files_versions.

@mrow4a
Copy link
Contributor

mrow4a commented Jan 5, 2023

Any chance to add some tests

Not sure if you mean unit tests or acceptance tests. The behavior to test is in the back-end implementation, so not directly visible to any API call. But we do have the testing app, and that has https://github.com/owncloud/testing/blob/master/lib/ServerFiles.php which allows access to "see" what files and directories exist in the back-end data storage.

So, I can add some acceptance tests that check the back-end storage behavior of files_versions.

I think what is meant here are unit tests in https://github.com/owncloud/core/blob/master/apps/files_versions/tests/VersioningTest.php

@DeepDiver1975
Copy link
Member

Unit tests it would be

@jvillafanez jvillafanez force-pushed the remove_empty_directory_versions branch 2 times, most recently from 5de7ed8 to 2fb5d51 Compare January 17, 2023 16:28
@DeepDiver1975
Copy link
Member

let's first merge #40531 to limit the rebase effort. THX

@pako81
Copy link

pako81 commented Feb 10, 2023

#40531 has been merged. Rebase this?

@jvillafanez jvillafanez force-pushed the remove_empty_directory_versions branch from 2fb5d51 to 74a336d Compare February 13, 2023 08:26
@phil-davis
Copy link
Contributor

LGTM. @DeepDiver1975 please review again.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

63.3% 63.3% Coverage
0.0% 0.0% Duplication

$this->assertCount(0, $results);
// empty folder should be deleted
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/');
$this->assertCount(0, $results);
Copy link
Member

Choose a reason for hiding this comment

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

old topic - self::assertCount() but this is all over our code base ....

@DeepDiver1975 DeepDiver1975 merged commit 135869c into master Feb 13, 2023
@delete-merged-branch delete-merged-branch bot deleted the remove_empty_directory_versions branch February 13, 2023 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants