Skip navigation

Already There FS

Say we’d like a ‘file system’ in which there is no material difference between whether files exists or not. Reading a file that doesn’t exist returns nil and setting a file to nil deletes it. Thus two of the methods in CRUD can be done without — all we need is read and write.

Would this make things more compact and straightforward or simply dense and confusing?

repo = FS.new('/root/of/fs')
repo['name/of/thing']  # returns textual value of thing
# => nil
repo['name/of/thing'] = 'new text'  # writes to thing
# => 'new text'
unless repo['name/of/thing/that/does/not/exist']
  "this thing doesn't exist!"
end
# => 'this thing doesn't exist!'

In this model, a filesystem is sort of hash. The only queer thing is the keys — some of them ‘belong’ to other keys, because of directories and such. Since this is an approach to a filesystem as a database, maybe we can do with out directories — after all, the user never needs to cd to them. So then we can have the repo accept regexen, so that we can grab the children of directories like this:

repo[%r|/some/project/.*|]
# => list of everything below /some/project/

Note that setting permissions, &c. gets a little weird in this model because we have to set them via regexen and not by directory. A user can create files in /some/project/ if they can write to /some/project/.*. Also, consider that /some/project matches a different regex and so is really a different resource… This corresponds to the way WebDAV looks at things; but it doesn’t mirror the Unix filesystem at all.

When files are versioned, they may be approached as lists of all their revisions.

  • a/b/c -> current revision of the file
  • a/b/c[-1] -> revision previous to this one
  • a/b/c[0] -> first ever revision

I’m not really sure what the Ruby syntax for this should be but you get the idea. Revisions are read only — they can not be set to nil or otherwise altered.

Advertisements

Post a Comment

You must be logged in to post a comment.
%d bloggers like this: