lib/store/digest.rb
# Add an object to the store. Takes pretty much anything that
# 
#
# @note Prefabricated {Store::Digest::Object} instances will be
#   rescanned.
#
# @note `:preserve` will cause a noop if object metadata is identical
#   save for `:ctime` and `:mtime` (`:ctime` is always ignored).
#
# @param obj [IO,File,Pathname,String,Store::Digest::Object] the object
# @param type [String] the content type
# @param charset [String] the character set, if applicable
# @param language [String] the language, if applicable
# @param encoding [String] the encoding (eg compression) if applicable
# @param mtime [Time] the modification time, if not "now"
# @param strict [true, false] strict checking on metadata input
# @param preserve [false, true] preserve existing modification time
# @return [Store::Digest::Object] The (potentially pre-existing) entry
Add an object to the store. Takes pretty much anything that
Add an object to the store . Takes pretty much anything that
def add obj, type: nil, charset: nil, language: nil, encoding: nil,
      mtime: nil, strict: true, preserve: false
    return unless obj
      obj = coerce_object obj, type: type, charset: charset,
        language: language, encoding: encoding, mtime: mtime, strict: strict
      raise ArgumentError, 'We need something to store!' unless obj.content?
      tmp = temp_blob
      obj.scan(digests: algorithms, blocksize: 2**20, strict: strict,
        type: type, charset: charset, language: language,
        encoding: encoding, mtime: mtime) do |buf|
        tmp << buf
      end
      obj.dtime = nil
      if h = set_meta(obj, preserve: preserve)
        content = obj.content
        if content.is_a? File
          path = Pathname(content.path).expand_path
          content = -> { path.open('rb') }
        end
        obj = Store::Digest::Object.new content, fresh: true, **h
        settle_blob obj[primary].digest, tmp, mtime: obj.mtime
      else
        tmp.close
        tmp.unlink
        obj = get obj
        obj.fresh? false 
      end
      obj
  end
def add obj , type : nil , charset : nil , language : nil , encoding : nil , mtime : nil , strict : true , preserve : false return unless obj obj = coerce_object obj , type : type , charset : charset , language : language , encoding : encoding , mtime : mtime , strict : strict raise ArgumentError , 'We need something to store!' unless obj . content? tmp = temp_blob obj . scan ( digests : algorithms , blocksize : 2 ** 20 , strict : strict , type : type , charset : charset , language : language , encoding : encoding , mtime : mtime ) do | buf | tmp << buf end obj . dtime = nil if h = set_meta ( obj , preserve : preserve ) content = obj . content if content . is_a? File path = Pathname ( content . path ) . expand_path content = -> { path . open ( 'rb' ) } end obj = Store :: Digest :: Object . new content , fresh : true , ** h settle_blob obj [ primary ] . digest , tmp , mtime : obj . mtime else tmp . close tmp . unlink obj = get obj obj . fresh? false end obj end
Add an object to the store.
Add an object to the store .
#transaction do # |txn| # XXX this is stupid; figure out a better way to do this # get our digests # if we are scanning an object it is necessarily not deleted # set_meta will return nil if there is no difference in what is set # replace the object # do this to prevent too many open files # now settle the blob into storage #txn.commit # eh just do this # object is not fresh since we already have it #end
The (potentially pre-existing) entry
The ( potentially pre - existing ) entry
Store::Digest::Object
obj
None
type
the content type
the content type
charset
the character set, if applicable
the character set if applicable
language
the language, if applicable
the language if applicable
encoding
the encoding  if applicable
the encoding if applicable
mtime
the modification time, if not "now"
the modification time if not " now "
strict
strict checking on metadata input
strict checking on metadata input
preserve
preserve existing modification time
preserve existing modification time
note
Prefabricated {Store::Digest::Object} instances will be rescanned.
Prefabricated { Store :: Digest :: Object } instances will be rescanned .
note
`:preserve` will cause a noop if object metadata is identical save for `:ctime` and `:mtime` (`:ctime` is always ignored).
` : preserve ` will cause a noop if object metadata is identical save for ` : ctime ` and ` : mtime ` ( ` : ctime ` is always ignored ) .