Skip to content

yfs and FileSystem needs to be changed to support rename file and directory. #56

@kifhan

Description

@kifhan

Description

MultiHack use this way to maintain files.

self.yfs.set(filePath, Y.Text)

but I found out this way you get really messy when you try to rename file or directory.

Because of this problem: Cannot change property's key name on y-map. You must delete obj from Y-map and insert again. But when you do that (delete and insert) you cannot use exist Y data type object (y-text, y-array, etc) because Y-Map set takes only TypeDefinition and creates new data type object.

Solution

My Solution is use two Y-map data.

filesystem_index: 'Map',
filesystem_nodes: 'Map'

Both filesystem_index and filesystem_nodes use randomly generated contentID as a key.
One contentID can access both file meta information (filesystem_index) and file content (filesystem_nodes).

Meta data looks like this.

self.yFSIndex.set(contentID, {
  name: filename,
  type: filetype,
  contentID: contentID,
  replydbID: replydbID,
  parentPath: parentPath
})

Feel free to check my implementation on Rellat.
I also fix few things on filesystem.js and main file (index.js).
One tricky thing is when you use _buildPath you can't guarantee to get right meta data at right timing.
So I made this sideway.

self.execWhenTargetSet = function (target, f) {
    function ft () {
      if (target) f()
      else setTimeout(ft, 50)
    }
    ft()
  }

I'm not sure this is best way but this works pretty well.

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