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. |
I would call error 2016-04-20 17:13 GMT+02:00 Valentin Ryckewaert <[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:
|
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]>:
|
2016-04-21 9:55 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
+1 |
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:
|
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]>:
|
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]>:
|
I don't see any difference in the implementation. Wrong copy/paste? But from the comments I am for it. :) |
In reply to this post by Valentin Ryckewaert
2016-04-26 10:34 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
But it is wrong? It same as ensureCreateFile |
In reply to this post by Valentin Ryckewaert
Hi, https://pharo.fogbugz.com/f/cases/18084/FileReference-EnsureCreateFile the issue report I just corrected it in the slice Peter, sorry for my mistake. 2016-04-26 10:34 GMT+02:00 Valentin Ryckewaert <[hidden email]>:
|
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 > 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 |
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 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 |
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 |
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 > |
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 > |
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]>:
|
Free forum by Nabble | Edit this page |