/usr/lib/ruby/1.8/moneta/file.rb is in libmoneta-ruby1.8 0.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | begin
require "xattr"
rescue LoadError
puts "You need the xattr gem to use the File moneta store"
exit
end
require "fileutils"
module Moneta
class File
class Expiration
def initialize(directory)
@directory = directory
end
def [](key)
attrs = xattr(key)
ret = Marshal.load(attrs.get("moneta_expires"))
rescue Errno::ENOENT, SystemCallError
end
def []=(key, value)
attrs = xattr(key)
attrs.set("moneta_expires", Marshal.dump(value))
end
def delete(key)
attrs = xattr(key)
attrs.remove("moneta_expires")
end
private
def xattr(key)
::Xattr.new(::File.join(@directory, key))
end
end
def initialize(options = {})
@directory = options[:path]
if ::File.file?(@directory)
raise StandardError, "The path you supplied #{@directory} is a file"
elsif !::File.exists?(@directory)
FileUtils.mkdir_p(@directory)
end
@expiration = Expiration.new(@directory)
end
module Implementation
def key?(key)
::File.exist?(path(key))
end
alias has_key? key?
def [](key)
if ::File.exist?(path(key))
Marshal.load(::File.read(path(key)))
end
end
def []=(key, value)
::File.open(path(key), "w") do |file|
contents = Marshal.dump(value)
file.puts(contents)
end
end
def delete(key)
value = self[key]
FileUtils.rm(path(key))
value
rescue Errno::ENOENT
end
def clear
FileUtils.rm_rf(@directory)
FileUtils.mkdir(@directory)
end
private
def path(key)
::File.join(@directory, key.to_s)
end
end
include Implementation
include Defaults
include Expires
end
end
|