Skip to content

FSMemoryStore isFile/isDirectory checks break when FFI package is loaded #16

@MariusDoe

Description

@MariusDoe

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):

value
	^self at: 1

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:

  1. Add something like fs[Memory]Node to Association, ByteArray, and Dictionary and send that instead of value in basicIs{File,Directory}:
  2. Add something like fsIs[Memory]{File,Directory} to Assocation, ByteArray, and Dictionary
  3. 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.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions