[Pharo-project] FSPath withExtension: bug
hi, FSPath>>#withExtension: is ignoring adding extension if extension is equal to end of basename. For example, if I want to produce: (FSFilesystem disk workingDirectory / 'Host') withExtension: 'st'. I should receive: /path/to/Host.st but I actually receive: /path/to/Host that can be fixed replacing FSPath>>#withExtension: extension | basename name | basename := self basename. ^ (basename endsWith: extension) ifTrue: [ self ] ifFalse: [name := basename copyUpToLast: self extensionDelimiter. self withName: name extension: extension] with: FSPath>>#withExtension: extension | basename name | basename := self basename. ^ (basename endsWith: '.', extension) ifTrue: [ self ] ifFalse: [name := basename copyUpToLast: self extensionDelimiter. self withName: name extension: extension] but I don't know if that would be a good solution :) best, Esteban
makes more sense to me On 2012-02-15, at 15:29, Esteban Lorenzano wrote:
hi,
FSPath>>#withExtension: is ignoring adding extension if extension is equal to end of basename.
For example, if I want to produce:
(FSFilesystem disk workingDirectory / 'Host') withExtension: 'st'.
I should receive:
/path/to/Host.st
but I actually receive:
/path/to/Host
that can be fixed replacing
FSPath>>#withExtension: extension | basename name | basename := self basename. ^ (basename endsWith: extension) ifTrue: [ self ] ifFalse: [name := basename copyUpToLast: self extensionDelimiter. self withName: name extension: extension]
with:
FSPath>>#withExtension: extension | basename name | basename := self basename. ^ (basename endsWith: '.', extension) ifTrue: [ self ] ifFalse: [name := basename copyUpToLast: self extensionDelimiter. self withName: name extension: extension]
but I don't know if that would be a good solution :)
best, Esteban
OK, but don't hardcode the extensionDelimiter :) Le 15 février 2012 16:20, Camillo Bruni <camillobruni@gmail.com> a écrit :
makes more sense to me On 2012-02-15, at 15:29, Esteban Lorenzano wrote:
hi,
FSPath>>#withExtension: Â is ignoring adding extension if extension is equal to end of basename.
For example, if I want to produce:
(FSFilesystem disk workingDirectory / 'Host') withExtension: 'st'.
I should receive:
/path/to/Host.st
but I actually receive:
/path/to/Host
that can be fixed replacing
FSPath>>#withExtension: extension    | basename name |    basename := self basename.    ^ (basename endsWith: extension)        ifTrue: [ self ]        ifFalse:            [name := basename copyUpToLast: self extensionDelimiter.            self withName: name extension: extension]
with:
FSPath>>#withExtension: extension    | basename name |    basename := self basename.    ^ (basename endsWith: '.', extension)        ifTrue: [ self ]        ifFalse:            [name := basename copyUpToLast: self extensionDelimiter.            self withName: name extension: extension]
but I don't know if that would be a good solution :)
best, Esteban
hmm.. i don't see if it will handle well a multiple extensions which sometimes is nice. (btw, why FS have to even care about it? a file name is a string. whatever you put there) Perhaps there should be two methods: one for adding extra extension (just unconditionally concatenate) and second for replacing extension #addExtension: + #changeExtension: (or #replaceExtension: ,if you want). Because what if i want to have extensions like .tar.gz? tarFile := (FSFilesystem disk workingDirectory / 'file.tar'). "zip stuff here" newName := tarFile addExtension: 'gz'. apparently new name should have .tar.gz extension while with current implementation of #withExtension: , it will replace the original one and put just .gz On 15 February 2012 19:42, Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com> wrote:
OK, but don't hardcode the extensionDelimiter :)
Le 15 février 2012 16:20, Camillo Bruni <camillobruni@gmail.com> a écrit :
makes more sense to me On 2012-02-15, at 15:29, Esteban Lorenzano wrote:
hi,
FSPath>>#withExtension: Â is ignoring adding extension if extension is equal to end of basename.
For example, if I want to produce:
(FSFilesystem disk workingDirectory / 'Host') withExtension: 'st'.
I should receive:
/path/to/Host.st
but I actually receive:
/path/to/Host
that can be fixed replacing
FSPath>>#withExtension: extension    | basename name |    basename := self basename.    ^ (basename endsWith: extension)        ifTrue: [ self ]        ifFalse:            [name := basename copyUpToLast: self extensionDelimiter.            self withName: name extension: extension]
with:
FSPath>>#withExtension: extension    | basename name |    basename := self basename.    ^ (basename endsWith: '.', extension)        ifTrue: [ self ]        ifFalse:            [name := basename copyUpToLast: self extensionDelimiter.            self withName: name extension: extension]
but I don't know if that would be a good solution :)
best, Esteban
-- Best regards, Igor Stasenko.
May be FS is over engineered (even if I would like to hear what camillo think because he work on GitFS shows that FS is powerful) I was reading http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FilePath and http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FileDescript... and I like what I read.
On 15 Feb 2012, at 21:51, Stéphane Ducasse wrote:
May be FS is over engineered (even if I would like to hear what camillo think because he work on GitFS shows that FS is powerful) I was reading http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FilePath and http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FileDescript...
and I like what I read.
Apparently they are adding Path objects to Java: http://codingjunkie.net/java-7-copy-move/
thanks I will read that carefully Stef On Feb 15, 2012, at 9:59 PM, Sven Van Caekenberghe wrote:
On 15 Feb 2012, at 21:51, Stéphane Ducasse wrote:
May be FS is over engineered (even if I would like to hear what camillo think because he work on GitFS shows that FS is powerful) I was reading http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FilePath and http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FileDescript...
and I like what I read.
Apparently they are adding Path objects to Java:
The intro is there http://codingjunkie.net/java7-file-revolution/ Stef On Feb 15, 2012, at 10:13 PM, Stéphane Ducasse wrote:
thanks I will read that carefully
Stef
On Feb 15, 2012, at 9:59 PM, Sven Van Caekenberghe wrote:
On 15 Feb 2012, at 21:51, Stéphane Ducasse wrote:
May be FS is over engineered (even if I would like to hear what camillo think because he work on GitFS shows that FS is powerful) I was reading http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FilePath and http://www.gnu.org/software/smalltalk/manual-base/gst-base.html#FileDescript...
and I like what I read.
Apparently they are adding Path objects to Java:
participants (6)
-
Camillo Bruni -
Esteban Lorenzano -
Igor Stasenko -
Nicolas Cellier -
Stéphane Ducasse -
Sven Van Caekenberghe