These two methods expect an Association:
|
basicIsFile: association |
|
^ association value isDictionary not |
|
basicIsDirectory: association |
|
^ association value isDictionary |
But in case they receive a
ByteArray or
Dictionary,
Object>>value comes to the rescue and prevents this code from breaking.
However, FFI-Kernel adds this method on
RawBitsArray (from which
ByteArray inherits):
This breaks the two methods above when they are given a ByteArray.
This actually happens quite often, e. g.:
|
createFile: aPath |
|
^ self |
|
nodeAt: aPath parent |
|
ifPresent: [ :dict | |
|
(self basicIsDirectory: dict) |
|
ifTrue: [ dict at: aPath basename put: ByteArray new ] ] |
|
ifAbsent: [ self signalDirectoryDoesNotExist: aPath parent ] |
Note that the other implementations usually return an "entry" (name -> node) rather than a plain "node" from
nodeAt:ifPresent:ifAbsent:, contrary to what the name might suggest.
I see a few ways to fix this, in increasing order of (estimated) amount of code changed:
- Add something like
fs[Memory]Node to Association, ByteArray, and Dictionary and send that instead of value in basicIs{File,Directory}:
- Add something like
fsIs[Memory]{File,Directory} to Assocation, ByteArray, and Dictionary
- Wrap the plain nodes in a temporary
Association before passing them to basicIs{File,Directory}:, as in self basicIsDirectory: '' -> dict. Although that feels the most ugly to me.
- Change
nodeAt:ifPresent:ifAbsent: to return the entry (Association) instead of the plain node (ByteArray/Dictionary) and adjust its senders, which can then pass the Assocation to basicIs{File,Directory}:. AFAICT, that would align its behavior more with the other implementations of it. Note that this would require us to give a name to the root node, which could be empty, i. e. self root = ('' -> Dictionary new), and we have to decide whether to store this Association or create it temporarily when needed.
These two methods expect an
Association:squeak-filesystem/src/FS-Memory.package/FSMemoryStore.class/instance/basicIsFile..st
Lines 2 to 3 in 74acb4a
squeak-filesystem/src/FS-Memory.package/FSMemoryStore.class/instance/basicIsDirectory..st
Lines 2 to 3 in 74acb4a
But in case they receive a
ByteArrayorDictionary,Object>>valuecomes to the rescue and prevents this code from breaking.However, FFI-Kernel adds this method on
RawBitsArray(from whichByteArrayinherits):This breaks the two methods above when they are given a
ByteArray.This actually happens quite often, e. g.:
squeak-filesystem/src/FS-Memory.package/FSMemoryStore.class/instance/createFile..st
Lines 2 to 8 in 74acb4a
Note that the other implementations usually return an "entry" (name -> node) rather than a plain "node" from
nodeAt:ifPresent:ifAbsent:, contrary to what the name might suggest.I see a few ways to fix this, in increasing order of (estimated) amount of code changed:
fs[Memory]NodetoAssociation,ByteArray, andDictionaryand send that instead ofvalueinbasicIs{File,Directory}:fsIs[Memory]{File,Directory}toAssocation,ByteArray, andDictionaryAssociationbefore passing them tobasicIs{File,Directory}:, as inself basicIsDirectory: '' -> dict. Although that feels the most ugly to me.nodeAt:ifPresent:ifAbsent:to return the entry (Association) instead of the plain node (ByteArray/Dictionary) and adjust its senders, which can then pass theAssocationtobasicIs{File,Directory}:. AFAICT, that would align its behavior more with the other implementations of it. Note that this would require us to give a name to the root node, which could be empty, i. e.self root = ('' -> Dictionary new), and we have to decide whether to store thisAssociationor create it temporarily when needed.