FuseFS

30分プログラム、その64。FuseFSで遊んでみる。
準備にだいぶ時間がかかった。

準備

  1. MacFUSE Coreを入れる
  2. FuseFSを入れる。

ただし、FuseFSはgemには登録されていないので、手動でインストールする必要がある。
さらに、Mac版は上記とは別に用意されている。

$ svn co http://svn.datanoise.com/fusefs-osx
$ cd fusefs-osx
$ make
$ sudo make install

コード

$ ruby hello.rb hoge

とすると、hoge以下にマウントされる。
hogeの内容は削除されるので注意。これでデククトップが消えて大変だった。ごみ箱に移動するだけみたいだけれども。

require 'fusefs'

class Hello
  def initialize
    @contents = ['hello.txt']
  end

  def contents(path)
    p path
    ['hello.txt']
  end

  def file?(path)
    p path
    path == '/hello.txt'
  end

  def read_file(path)
    "hello\n"
  end

  def size(path)
    read_file(path).size
  end
end

hello = Hello.new
FuseFS.set_root hello
FuseFS.mount_under ARGV.shift
FuseFS.run
  • まだexampleの丸写し。
  • 明日はこれをもっと発展させる