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

Sometimes directories don't get deleted #7

Closed
ufobat opened this issue Jan 21, 2019 · 1 comment
Closed

Sometimes directories don't get deleted #7

ufobat opened this issue Jan 21, 2019 · 1 comment

Comments

@ufobat
Copy link
Owner

ufobat commented Jan 21, 2019

While using this module i realized that directories (with their content) don't get deleted. It doesn't happen all the time so it's some kind of race condition.

@ufobat
Copy link
Owner Author

ufobat commented Jan 21, 2019

Documented behaviour

Quote of the README:

Note that deletion will happen only if the path was created by this module. Doing make-temp-dir.sibling: 'foo' will still give you an IO::Path with Temp::Path::AutoDel mixed in due to how IO::Path methods create new objects, but that new object created by '.sibling' won't be deleted, because you created it and not the module.

As described in the documentation of the module, siblings of directories should not be deleted, because you created them and not the module itself. This can only be achived if the module is no longer supposed to delete a directory, as son as you create some content inside the directory. Deleting the directory would cause the deletion of the files inside it.

Implementation of this feature

In order to not delete the siblings that have the mixin as well there is the forget command. As soon as DESTROY of a sibling gets called the module wont delete its parent directory anymore.

There are two issues with this approach:

  1. This reflects on the objects of IO::Path you might have in your memory, not what files exists on the filesystem. As soon as you create a sibling there shout be no removal of the $dir even if the directory stayed empty for all the time:
my $dir = make-temp-dir;
my $file = $dir.add('does-not-exist-on-fs'); # no spurt or something

  1. DESTROY only gets called when an obects gets garbage collected. Afaik there is no global destruction phase this means that you might have $file.DESTROY being called, maybe not. Even if you can ensure that all DESTROY methods get invoked you can still assume that the END { $Channel.send: ('nuke', ); ...} has been called before so you're can't let this module forgetyour $dir. This means that this behaviour is not deterministic.

My suggestion

I would suggest to change forget into ignore. This means that if you have a $file (sibling) that gets DESTROYed you don't delete the file on disk, but you keep it untill the $dir gets DESTROYed (and therefork nuked form disk) or the programm terminates and the END phaser gets called ( and nukes all remaining files/directories)

(Having all temp directories being deleted when the program terminates is what I was expecting before I read the documentation.)

AlexDaniel added a commit that referenced this issue Jan 22, 2019
Fixed issue #7 according to my suggestion - temp dirs will always be …
@ufobat ufobat closed this as completed Jan 31, 2019
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

No branches or pull requests

1 participant