#encoding: utf-8 require "simple_fs/version" module SimpleFS require 'simple_fs/file_pool' require "sequel" class FS def initialize(fs_path) Dir.mkdir fs_path unless Dir.exist? fs_path @file_pool = FilePool::Pool.new File.join(fs_path, 'pool') @db = create_index_db File.join(fs_path, 'index.db') end def move(old_path, new_path, optopns = {}) @db[:index].where(:path => old_path).update(:path => new_path) end def copy(old_path, new_path, optopns = {}) @old = @db[:index].where(:path => old_path).first @db[:index].insert(:path => new_path, :file_id => @old[:file_id]) end def remove(path, optopns = {}) @db[:index].where(:path => path).delete end def create(path, data, optopns = {}) file_id = @file_pool.puts data @db[:index].insert(:path => path, :file_id => file_id) end private def create_index_db db_path db = Sequel.sqlite(db_path) unless db.table_exists? :index db.create_table :index do primary_key :id String :file_id String :path end end return db end end end