ensureCreateFile

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

ensureCreateFile

Valentin Ryckewaert
Hi,

I would like to have your opinion about what you want ensureCreateFile to do.
According to me ensureCreateFile should do the same thing as ensureCreateDirectory + create the file in the last directory given but in its implementation if the parents of this file doesn't exist we get an Exception.

Is it wanted or an error? 

Valentin.
Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Denis Kudriashov
I would call error

2016-04-20 17:13 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Hi,

I would like to have your opinion about what you want ensureCreateFile to do.
According to me ensureCreateFile should do the same thing as ensureCreateDirectory + create the file in the last directory given but in its implementation if the parents of this file doesn't exist we get an Exception.

Is it wanted or an error? 

Valentin.

Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Peter Uhnak
At least in unix creating files and folders are different operations (mkdir/touch, rm/rmdir).

And even though it may seem convenient I would argue that it will create unintentional issues — if you have incorrect folder it will silently create errornous structure on the disk instead of throwing error. Imho overloading ensureCreateFile is bad.

But there's nothing stopping you from extending AFR and adding an extra method:

AbstractFileReference>>ensureCreateFileAndDirectory
"Create if necessary a folder and file for the receiver."

self parent ensureCreateDirectory.
self ensureCreateFile


Peter

On Wed, Apr 20, 2016 at 6:16 PM, Denis Kudriashov <[hidden email]> wrote:
I would call error

2016-04-20 17:13 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Hi,

I would like to have your opinion about what you want ensureCreateFile to do.
According to me ensureCreateFile should do the same thing as ensureCreateDirectory + create the file in the last directory given but in its implementation if the parents of this file doesn't exist we get an Exception.

Is it wanted or an error? 

Valentin.


Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Valentin Ryckewaert
Yes but why ensureCreateFile then ?
Why don't we juste create a message createFile as there is createFolder ?
createFolder : create the folder
createFile : create the file

ensureCreateFolder : create the folder and its parents if necessary
ensureCreateFile : create the file and its parents if necessary

2016-04-21 9:46 GMT+02:00 Peter Uhnák <[hidden email]>:
At least in unix creating files and folders are different operations (mkdir/touch, rm/rmdir).

And even though it may seem convenient I would argue that it will create unintentional issues — if you have incorrect folder it will silently create errornous structure on the disk instead of throwing error. Imho overloading ensureCreateFile is bad.

But there's nothing stopping you from extending AFR and adding an extra method:

AbstractFileReference>>ensureCreateFileAndDirectory
"Create if necessary a folder and file for the receiver."

self parent ensureCreateDirectory.
self ensureCreateFile


Peter

On Wed, Apr 20, 2016 at 6:16 PM, Denis Kudriashov <[hidden email]> wrote:
I would call error

2016-04-20 17:13 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Hi,

I would like to have your opinion about what you want ensureCreateFile to do.
According to me ensureCreateFile should do the same thing as ensureCreateDirectory + create the file in the last directory given but in its implementation if the parents of this file doesn't exist we get an Exception.

Is it wanted or an error? 

Valentin.



Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Denis Kudriashov

2016-04-21 9:55 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Yes but why ensureCreateFile then ?
Why don't we juste create a message createFile as there is createFolder ?
createFolder : create the folder
createFile : create the file

ensureCreateFolder : create the folder and its parents if necessary
ensureCreateFile : create the file and its parents if necessary

+1
Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Peter Uhnak
because it's like this

ensureCreateFolder : create the folder structure if necessary
ensureCreateFile : create the file if necessary

I really don't see any gain from changing existing behavior and introducing potential problems.
If I ask for file to be created, I don't expect that the system will suddenly start creating folders, that's a unintentional side effect.
If you need it for your convenience, then it's dead-easy to implement without breaking existing stuff.


On Thu, Apr 21, 2016 at 10:35 AM, Denis Kudriashov <[hidden email]> wrote:

2016-04-21 9:55 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Yes but why ensureCreateFile then ?
Why don't we juste create a message createFile as there is createFolder ?
createFolder : create the folder
createFile : create the file

ensureCreateFolder : create the folder and its parents if necessary
ensureCreateFile : create the file and its parents if necessary

+1

Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Valentin Ryckewaert
For me ensureCreateFolder is made to be sure the folder is created, if you make '/home/a/b/c/d' with a b c d not existing it will create all of them.
ensureCreateFile should do the same thing no ?

2016-04-21 13:19 GMT+02:00 Peter Uhnák <[hidden email]>:
because it's like this

ensureCreateFolder : create the folder structure if necessary
ensureCreateFile : create the file if necessary

I really don't see any gain from changing existing behavior and introducing potential problems.
If I ask for file to be created, I don't expect that the system will suddenly start creating folders, that's a unintentional side effect.
If you need it for your convenience, then it's dead-easy to implement without breaking existing stuff.


On Thu, Apr 21, 2016 at 10:35 AM, Denis Kudriashov <[hidden email]> wrote:

2016-04-21 9:55 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Yes but why ensureCreateFile then ?
Why don't we juste create a message createFile as there is createFolder ?
createFolder : create the folder
createFile : create the file

ensureCreateFolder : create the folder and its parents if necessary
ensureCreateFile : create the file and its parents if necessary

+1


Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Valentin Ryckewaert
Hi !

I made this if it's ok for you i'll post it on fogbugs :

AbstractFileReference
createFile
"Create if necessary a file for the receiver. If the parent does not exist return an exception"
self parent ensureCreateDirectory.
self writeStream close.
createDirectory
"Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents does not exist return an exception"
self parent exists ifFalse:[self error:'The parent directory does not exist'].
^ self resolve ensureCreateDirectory
ensureCreateFile
"Create if necessary a file for the receiver. If the parent does not exist creates it"
self parent ensureCreateDirectory.
self writeStream close.
ensureCreateDirectory "Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents folder does not exist create it" ^ self resolve ensureCreateDirectory

2016-04-26 10:34 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Hi !

I made this if it's ok for you i'll post it on fogbugs :

AbstractFileReference
createFile
"Create if necessary a file for the receiver. If the parent does not exist return an exception"
self parent ensureCreateDirectory.
self writeStream close.
createDirectory
"Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents does not exist return an exception"
self parent exists ifFalse:[self error:'The parent directory does not exist'].
^ self resolve ensureCreateDirectory
ensureCreateFile
"Create if necessary a file for the receiver. If the parent does not exist creates it"
self parent ensureCreateDirectory.
self writeStream close.
ensureCreateDirectory "Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents folder does not exist create it" ^ self resolve ensureCreateDirectory


2016-04-25 16:28 GMT+02:00 Stéphane Ducasse <[hidden email]>:
oui moi aussi 
je me demandais si on devait introduire une autre methode mais en fait 
le nouveau comportement est compatible donc je le ferais. 


On 25 Apr 2016, at 13:58, Valentin Ryckewaert <[hidden email]> wrote:

Tu en penses quoi toi ?
Je trouve ça illogique que ensureCreate ne signifie pas la meme chose pour un dossier ou pour un fichier.

---------- Forwarded message ----------
From: Valentin Ryckewaert <[hidden email]>
Date: 2016-04-22 10:11 GMT+02:00
Subject: Re: [Pharo-users] ensureCreateFile
To: Any question about pharo is welcome <[hidden email]>


For me ensureCreateFolder is made to be sure the folder is created, if you make '/home/a/b/c/d' with a b c d not existing it will create all of them.
ensureCreateFile should do the same thing no ?

2016-04-21 13:19 GMT+02:00 Peter Uhnák <[hidden email]>:
because it's like this

ensureCreateFolder : create the folder structure if necessary
ensureCreateFile : create the file if necessary

I really don't see any gain from changing existing behavior and introducing potential problems.
If I ask for file to be created, I don't expect that the system will suddenly start creating folders, that's a unintentional side effect.
If you need it for your convenience, then it's dead-easy to implement without breaking existing stuff.


On Thu, Apr 21, 2016 at 10:35 AM, Denis Kudriashov <[hidden email]> wrote:

2016-04-21 9:55 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Yes but why ensureCreateFile then ?
Why don't we juste create a message createFile as there is createFolder ?
createFolder : create the folder
createFile : create the file

ensureCreateFolder : create the folder and its parents if necessary
ensureCreateFile : create the file and its parents if necessary

+1




--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
03 59 57 78 50
03 59 35 86 16

S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France



Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Peter Uhnak

AbstractFileReference
createFile
"Create if necessary a file for the receiver. If the parent does not exist return an exception"
self parent ensureCreateDirectory.
self writeStream close.

ensureCreateFile
"Create if necessary a file for the receiver. If the parent does not exist creates it"
self parent ensureCreateDirectory.
self writeStream close.

I don't see any difference in the implementation. Wrong copy/paste?
But from the comments I am for it. :)
Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Denis Kudriashov
In reply to this post by Valentin Ryckewaert

2016-04-26 10:34 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
createFile
"Create if necessary a file for the receiver. If the parent does not exist return an exception"
self parent ensureCreateDirectory.
self writeStream close.

But it is wrong? It same as ensureCreateFile
Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Valentin Ryckewaert
In reply to this post by Valentin Ryckewaert
Hi,


I just corrected it in the slice Peter, sorry for my mistake.

2016-04-26 10:34 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Hi !

I made this if it's ok for you i'll post it on fogbugs :

AbstractFileReference
createFile
"Create if necessary a file for the receiver. If the parent does not exist return an exception"
self parent ensureCreateDirectory.
self writeStream close.
createDirectory
"Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents does not exist return an exception"
self parent exists ifFalse:[self error:'The parent directory does not exist'].
^ self resolve ensureCreateDirectory
ensureCreateFile
"Create if necessary a file for the receiver. If the parent does not exist creates it"
self parent ensureCreateDirectory.
self writeStream close.
ensureCreateDirectory "Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents folder does not exist create it" ^ self resolve ensureCreateDirectory

2016-04-26 10:34 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Hi !

I made this if it's ok for you i'll post it on fogbugs :

AbstractFileReference
createFile
"Create if necessary a file for the receiver. If the parent does not exist return an exception"
self parent ensureCreateDirectory.
self writeStream close.
createDirectory
"Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents does not exist return an exception"
self parent exists ifFalse:[self error:'The parent directory does not exist'].
^ self resolve ensureCreateDirectory
ensureCreateFile
"Create if necessary a file for the receiver. If the parent does not exist creates it"
self parent ensureCreateDirectory.
self writeStream close.
ensureCreateDirectory "Verifies that the directory does not exist and only creates if necessary. Do not remove files contained if they exist.If the parents folder does not exist create it" ^ self resolve ensureCreateDirectory


2016-04-25 16:28 GMT+02:00 Stéphane Ducasse <[hidden email]>:
oui moi aussi 
je me demandais si on devait introduire une autre methode mais en fait 
le nouveau comportement est compatible donc je le ferais. 


On 25 Apr 2016, at 13:58, Valentin Ryckewaert <[hidden email]> wrote:

Tu en penses quoi toi ?
Je trouve ça illogique que ensureCreate ne signifie pas la meme chose pour un dossier ou pour un fichier.

---------- Forwarded message ----------
From: Valentin Ryckewaert <[hidden email]>
Date: 2016-04-22 10:11 GMT+02:00
Subject: Re: [Pharo-users] ensureCreateFile
To: Any question about pharo is welcome <[hidden email]>


For me ensureCreateFolder is made to be sure the folder is created, if you make '/home/a/b/c/d' with a b c d not existing it will create all of them.
ensureCreateFile should do the same thing no ?

2016-04-21 13:19 GMT+02:00 Peter Uhnák <[hidden email]>:
because it's like this

ensureCreateFolder : create the folder structure if necessary
ensureCreateFile : create the file if necessary

I really don't see any gain from changing existing behavior and introducing potential problems.
If I ask for file to be created, I don't expect that the system will suddenly start creating folders, that's a unintentional side effect.
If you need it for your convenience, then it's dead-easy to implement without breaking existing stuff.


On Thu, Apr 21, 2016 at 10:35 AM, Denis Kudriashov <[hidden email]> wrote:

2016-04-21 9:55 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
Yes but why ensureCreateFile then ?
Why don't we juste create a message createFile as there is createFolder ?
createFolder : create the folder
createFile : create the file

ensureCreateFolder : create the folder and its parents if necessary
ensureCreateFile : create the file and its parents if necessary

+1




--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
03 59 57 78 50
03 59 35 86 16

S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France




Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

CyrilFerlicot
In reply to this post by Valentin Ryckewaert


On 26/04/2016 10:34, Valentin Ryckewaert wrote:

> Hi !
>
> I made this if it's ok for you i'll post it on fogbugs :
>
> AbstractFileReference
> createFile
> "Create if necessary a file for the receiver. If the parent does not
> exist return an exception"
> self parent ensureCreateDirectory.
> self writeStream close.
> createDirectory
> "Verifies that the directory does not exist and only creates if
> necessary. Do not remove files contained if they exist.If the parents
> does not exist return an exception"
> self parent exists ifFalse:[self error:'The parent directory does not
> exist'].
> ^ self resolve ensureCreateDirectory
> ensureCreateFile
> "Create if necessary a file for the receiver. If the parent does not
> exist creates it"
> self parent ensureCreateDirectory.
> self writeStream close.
> ensureCreateDirectory "Verifies that the directory does not exist and
> only creates if necessary. Do not remove files contained if they
> exist.If the parents folder does not exist create it" ^ self resolve
> ensureCreateDirectory
>
Hi,

I think that createDirectory should raise a FileDoesNotExist instead of
an Exception.

BTW, this may be good to discuss in another issue but we have a
FileDoesNotExistException and a FileDoesNotExist in the image. Maybe we
can unify both? Or if there is a difference we can explain it in the
class comment because I don't see the difference.

--
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France


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

Re: ensureCreateFile

Valentin Ryckewaert
I used this because here it's the folder which doesn't exist so I didn't know if FileDoesNotExist were a good idea, here it's as you want.

2016-04-26 11:24 GMT+02:00 Cyril Ferlicot Delbecque <[hidden email]>:


On 26/04/2016 10:34, Valentin Ryckewaert wrote:
> Hi !
>
> I made this if it's ok for you i'll post it on fogbugs :
>
> AbstractFileReference
> createFile
> "Create if necessary a file for the receiver. If the parent does not
> exist return an exception"
> self parent ensureCreateDirectory.
> self writeStream close.
> createDirectory
> "Verifies that the directory does not exist and only creates if
> necessary. Do not remove files contained if they exist.If the parents
> does not exist return an exception"
> self parent exists ifFalse:[self error:'The parent directory does not
> exist'].
> ^ self resolve ensureCreateDirectory
> ensureCreateFile
> "Create if necessary a file for the receiver. If the parent does not
> exist creates it"
> self parent ensureCreateDirectory.
> self writeStream close.
> ensureCreateDirectory "Verifies that the directory does not exist and
> only creates if necessary. Do not remove files contained if they
> exist.If the parents folder does not exist create it" ^ self resolve
> ensureCreateDirectory
>

Hi,

I think that createDirectory should raise a FileDoesNotExist instead of
an Exception.

BTW, this may be good to discuss in another issue but we have a
FileDoesNotExistException and a FileDoesNotExist in the image. Maybe we
can unify both? Or if there is a difference we can explain it in the
class comment because I don't see the difference.

--
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France


Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

CyrilFerlicot


On 26/04/2016 11:31, Valentin Ryckewaert wrote:
> I used this because here it's the folder which doesn't exist so I didn't
> know if FileDoesNotExist were a good idea, here it's as you want.
>

In Unix (at least) a directory is a file. I don't know if it's the same
in Windows. So in my opinion it's a good idea to raise a
"FileDoesNotExist".

--
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France


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

Re: ensureCreateFile

CyrilFerlicot
In reply to this post by Valentin Ryckewaert


On 26/04/2016 11:31, Valentin Ryckewaert wrote:
> I used this because here it's the folder which doesn't exist so I didn't
> know if FileDoesNotExist were a good idea, here it's as you want.
>

In fact I did not see but there is also a DirectoryDoesNotExist :)

--
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France


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

Re: ensureCreateFile

Sven Van Caekenberghe-2
In reply to this post by CyrilFerlicot
Why not make a subclass of FileDoesNotExist, DirectoryDoesNotExist - it is almost the same, but more specific.

Good exceptions are really important.

> On 26 Apr 2016, at 11:44, Cyril Ferlicot Delbecque <[hidden email]> wrote:
>
>
>
> On 26/04/2016 11:31, Valentin Ryckewaert wrote:
>> I used this because here it's the folder which doesn't exist so I didn't
>> know if FileDoesNotExist were a good idea, here it's as you want.
>>
>
> In Unix (at least) a directory is a file. I don't know if it's the same
> in Windows. So in my opinion it's a good idea to raise a
> "FileDoesNotExist".
>
> --
> Cyril Ferlicot
>
> http://www.synectique.eu
>
> 165 Avenue Bretagne
> Lille 59000 France
>


Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Sven Van Caekenberghe-2
In reply to this post by CyrilFerlicot

> On 26 Apr 2016, at 11:49, Cyril Ferlicot Delbecque <[hidden email]> wrote:
>
>
>
> On 26/04/2016 11:31, Valentin Ryckewaert wrote:
>> I used this because here it's the folder which doesn't exist so I didn't
>> know if FileDoesNotExist were a good idea, here it's as you want.
>>
>
> In fact I did not see but there is also a DirectoryDoesNotExist :)

Dub, I should have looked first ;-)

> --
> Cyril Ferlicot
>
> http://www.synectique.eu
>
> 165 Avenue Bretagne
> Lille 59000 France
>


Reply | Threaded
Open this post in threaded view
|

Re: ensureCreateFile

Valentin Ryckewaert
I sent a new slice, check it and say me if it's ok for you :)

2016-04-26 11:51 GMT+02:00 Sven Van Caekenberghe <[hidden email]>:

> On 26 Apr 2016, at 11:49, Cyril Ferlicot Delbecque <[hidden email]> wrote:
>
>
>
> On 26/04/2016 11:31, Valentin Ryckewaert wrote:
>> I used this because here it's the folder which doesn't exist so I didn't
>> know if FileDoesNotExist were a good idea, here it's as you want.
>>
>
> In fact I did not see but there is also a DirectoryDoesNotExist :)

Dub, I should have looked first ;-)

> --
> Cyril Ferlicot
>
> http://www.synectique.eu
>
> 165 Avenue Bretagne
> Lille 59000 France
>