AbstractFileReference>>ensureDelete when directory has children

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

AbstractFileReference>>ensureDelete when directory has children

CyrilFerlicot
Hello,

I often was surprise to get primitive failures while calling
#ensureDelete. I saw that when a folder has children, we should not call
#ensureDelete but #ensureDeleteAll, at least on Windows.

I think we should raise an other error than "Primitive Failure" when we
are in that case. Something like "DirectoryHasChildren" that would
signal "This directory contains files and cannot be deleted.".

What do you think?

--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France


signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: AbstractFileReference>>ensureDelete when directory has children

Peter Uhnak
Something like "DirectoryHasChildren" that would
signal "This directory contains files and cannot be deleted.".

+1

The only problem may be that even the VM doesn't actually know the reason (it could just trigger the delete at vm-level which will just return a failure state).

Peter
Reply | Threaded
Open this post in threaded view
|

Re: AbstractFileReference>>ensureDelete when directory has children

CyrilFerlicot
Le 20/08/2017 à 19:53, Peter Uhnák a écrit :
>
> +1
>
> The only problem may be that even the VM doesn't actually know the
> reason (it could just trigger the delete at vm-level which will just
> return a failure state).
>
> Peter

The fact that is touch the vm is a reason I post here. It would be good
to have the advice of people knowing the FS management to know the best
way to do this.

--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France


signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: AbstractFileReference>>ensureDelete when directory has children

alistairgrant
On Sun, Aug 20, 2017 at 07:55:45PM +0200, Cyril Ferlicot D. wrote:

> Le 20/08/2017 ?? 19:53, Peter Uhn??k a ??crit :
> >
> > +1
> >
> > The only problem may be that even the VM doesn't actually know the
> > reason (it could just trigger the delete at vm-level which will just
> > return a failure state).
> >
> > Peter
>
> The fact that is touch the vm is a reason I post here. It would be good
> to have the advice of people knowing the FS management to know the best
> way to do this.


File deletion isn't handled directly by the VM, but by FilePlugin.

I consider myself a beginner at VM plugins, but since no-one else has
answered yet, my 2c:

Modifying the directory deletion code is not as easy as one would like since
there is a version per platform.  At the moment there are six
(assuming I've counted correctly): win32, Mac OS, iOS, RiscOS, Plan9,
unix  (iOS is a .m file, Objective-C presumably).  However it looks like
it will still be reasonably straight-foward since the functions return a
boolean indicating success or failure, so it shouldn't be too difficult
to convert this to a status code.  I might have a go at this
after my first plugin is accepted (but I can't make any promise).

If no-one else makes the change and you don't want to wait, there are a
couple of other options that don't require modification of the plugin:

1. Modify DiskStore>>delete: to check pre-conditions such as the
   directory being empty.  While this is probably safe for checking that
   the directory is empty, for the more general case it is difficult
   since it will need to take in to account any difference in behaviour
   across platforms.

2. Modify the primitive failure handling code in
   FilePluginPrims>>deleteDirectory: to take a
   guess at why the primitive failed, e.g. is the directory empty.
   I think this is the safer approach since at least we already know
   that something has gone wrong.


Cheers,
Alistair