[Pharo-project] FileReference should throw error when deleting unexisting files?

Mariano Martinez Peck marianopeck at gmail.com
Mon Jun 11 15:17:24 EDT 2012

On Mon, Jun 11, 2012 at 8:38 PM, Mariano Martinez Peck <
marianopeck at gmail.com> wrote:

> So if we now do:
>  'afileThatDoesntExist' asFileReference delete
> I get a PrimitiveFailed. If this is what we want, can I add:
> FileReference >> deleteIfExists
> self exists ifTrue: [ self delete]

So I discussed in IRC and Camillo and Sean recommended to use #ensureDelete
because it is concistent to ensureFile and ensureDirecotry etc...
for me #ensureDelete sounds the opposite to what this method does because I
am not ensuring anything, if fact, I won't remove anything if the file does
not exist.
Camilo also suggested to do

FileReference >> deleteIfExists

self deleteIfAbsent: [ ]

FileReference >> deleteIfAbsent: aBlock

self exists
      ifTrue: [self delete]
      ifFalse: [aBock value]

What do you think? which one do you like more?  #ensureDelete or
do you also agree to add the intermediate #deleteIfAbsent:  ?


> or something like that?   because lots of places (tearDown of tests) I
> want to remove crao which may or may not exist...
> thanks
> --
> Mariano
> http://marianopeck.wordpress.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20120611/6d8b12cb/attachment.html>

More information about the Pharo-dev mailing list