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

Cleanup files.PublishedStorage after dropping a publish #1381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aol-nnov
Copy link
Contributor

@aol-nnov aol-nnov commented Oct 22, 2024

Fixes: #198

After dropping files.PublishedStorage there were some leftovers - empty directory tree. If that directory tree is empty, it is now removed.

Checklist

  • unit-test added (if change is algorithm)
  • functional test added/updated (if change is functional)

@aol-nnov
Copy link
Contributor Author

@neolynx here is another annoying thing I'd like to fix in aptly. My publish prefix is bloated with empty directories as I have to create and remove publishes intensively.

@neolynx
Copy link
Member

neolynx commented Oct 22, 2024

oh, yes please ! I found this quite annoying as well...

@aol-nnov
Copy link
Contributor Author

yay, there is an issue for it! #198

filepath.Join(storage.rootPath,
strings.Join(segments[:segmentsCount], "/")))

if err != nil && strings.Contains(err.Error(), "directory not empty") {
Copy link
Member

@neolynx neolynx Oct 22, 2024

Choose a reason for hiding this comment

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

could we rather check if it is empty before removing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, in theory, but it is a lot more code, than checking an error...

Copy link
Member

Choose a reason for hiding this comment

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

i know, but it is also more proper, to not accidentally delete stuff :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not agree with you. Also, it is algorithmically more complex to perform the check you propose.

In general, the question is: why do you trust one syscall and do not trust another?

Copy link
Member

Choose a reason for hiding this comment

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

I think it is a question of taste... ;-) in some industries it is even not allowed to rely on error text, ... not a question of trusting sys calls..

in aptly I would prefer the check before action, we could add a function to utils/utils.go:

func isDirEmpty(path string) (bool, error) {
	f, err := os.Open(path)
	if err != nil {
		return false, err
	}
	defer f.Close()

	contents, err := f.Readdirnames(1) // Read only 1 file to check if it's empty
	if err != nil {
		return false, err
	}

	return len(contents) == 0, nil
}

and just call this before the os.Remove call. I would not worry about algorithic complexity with a low number of nested directories..

what do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look, even if os.Remove broke and start removing non-empty directories, it won't go beyond publish root. Also, if any of publishes are accidentally lost (which I highly doubt), they could be recreated from corresponding repos.

Anyway, I'm out of office for today and do not have a laptop at hand. Let's get back to it tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, if the root of your comment is that it is no good checking error text, we could simply bail out on any error. It is perfectly fine also.

Copy link
Member

Choose a reason for hiding this comment

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

Look, the file system might also be on a NFS server, and I would like aptly to check before a remove action and have syscalls return errors on real errors. Yes it works both ways, but here in aptly i feel we should do it this way ;-)

Aside from this, there are some tests failing, maybe the tests were wrong, relying on the empty directory ?

deb/publish.go Outdated Show resolved Hide resolved
After dropping files.PublishedStorage there were some leftovers -
empty directory tree. If that directory tree is empty, it is now removed.
@aol-nnov aol-nnov requested a review from neolynx October 22, 2024 14:44
@neolynx neolynx self-assigned this Oct 22, 2024
@neolynx neolynx added the fix tests Tests are failing label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix tests Tests are failing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aptly leave empty directory structure when droping published repo with prefix
2 participants