Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/usr/share/ruby
File: pstore.rb
# frozen_string_literal: true
[0] Fix | Delete
# = PStore -- Transactional File Storage for Ruby Objects
[1] Fix | Delete
#
[2] Fix | Delete
# pstore.rb -
[3] Fix | Delete
# originally by matz
[4] Fix | Delete
# documentation by Kev Jackson and James Edward Gray II
[5] Fix | Delete
# improved by Hongli Lai
[6] Fix | Delete
#
[7] Fix | Delete
# See PStore for documentation.
[8] Fix | Delete
[9] Fix | Delete
require "digest"
[10] Fix | Delete
[11] Fix | Delete
#
[12] Fix | Delete
# PStore implements a file based persistence mechanism based on a Hash. User
[13] Fix | Delete
# code can store hierarchies of Ruby objects (values) into the data store file
[14] Fix | Delete
# by name (keys). An object hierarchy may be just a single object. User code
[15] Fix | Delete
# may later read values back from the data store or even update data, as needed.
[16] Fix | Delete
#
[17] Fix | Delete
# The transactional behavior ensures that any changes succeed or fail together.
[18] Fix | Delete
# This can be used to ensure that the data store is not left in a transitory
[19] Fix | Delete
# state, where some values were updated but others were not.
[20] Fix | Delete
#
[21] Fix | Delete
# Behind the scenes, Ruby objects are stored to the data store file with
[22] Fix | Delete
# Marshal. That carries the usual limitations. Proc objects cannot be
[23] Fix | Delete
# marshalled, for example.
[24] Fix | Delete
#
[25] Fix | Delete
# == Usage example:
[26] Fix | Delete
#
[27] Fix | Delete
# require "pstore"
[28] Fix | Delete
#
[29] Fix | Delete
# # a mock wiki object...
[30] Fix | Delete
# class WikiPage
[31] Fix | Delete
# def initialize( page_name, author, contents )
[32] Fix | Delete
# @page_name = page_name
[33] Fix | Delete
# @revisions = Array.new
[34] Fix | Delete
#
[35] Fix | Delete
# add_revision(author, contents)
[36] Fix | Delete
# end
[37] Fix | Delete
#
[38] Fix | Delete
# attr_reader :page_name
[39] Fix | Delete
#
[40] Fix | Delete
# def add_revision( author, contents )
[41] Fix | Delete
# @revisions << { :created => Time.now,
[42] Fix | Delete
# :author => author,
[43] Fix | Delete
# :contents => contents }
[44] Fix | Delete
# end
[45] Fix | Delete
#
[46] Fix | Delete
# def wiki_page_references
[47] Fix | Delete
# [@page_name] + @revisions.last[:contents].scan(/\b(?:[A-Z]+[a-z]+){2,}/)
[48] Fix | Delete
# end
[49] Fix | Delete
#
[50] Fix | Delete
# # ...
[51] Fix | Delete
# end
[52] Fix | Delete
#
[53] Fix | Delete
# # create a new page...
[54] Fix | Delete
# home_page = WikiPage.new( "HomePage", "James Edward Gray II",
[55] Fix | Delete
# "A page about the JoysOfDocumentation..." )
[56] Fix | Delete
#
[57] Fix | Delete
# # then we want to update page data and the index together, or not at all...
[58] Fix | Delete
# wiki = PStore.new("wiki_pages.pstore")
[59] Fix | Delete
# wiki.transaction do # begin transaction; do all of this or none of it
[60] Fix | Delete
# # store page...
[61] Fix | Delete
# wiki[home_page.page_name] = home_page
[62] Fix | Delete
# # ensure that an index has been created...
[63] Fix | Delete
# wiki[:wiki_index] ||= Array.new
[64] Fix | Delete
# # update wiki index...
[65] Fix | Delete
# wiki[:wiki_index].push(*home_page.wiki_page_references)
[66] Fix | Delete
# end # commit changes to wiki data store file
[67] Fix | Delete
#
[68] Fix | Delete
# ### Some time later... ###
[69] Fix | Delete
#
[70] Fix | Delete
# # read wiki data...
[71] Fix | Delete
# wiki.transaction(true) do # begin read-only transaction, no changes allowed
[72] Fix | Delete
# wiki.roots.each do |data_root_name|
[73] Fix | Delete
# p data_root_name
[74] Fix | Delete
# p wiki[data_root_name]
[75] Fix | Delete
# end
[76] Fix | Delete
# end
[77] Fix | Delete
#
[78] Fix | Delete
# == Transaction modes
[79] Fix | Delete
#
[80] Fix | Delete
# By default, file integrity is only ensured as long as the operating system
[81] Fix | Delete
# (and the underlying hardware) doesn't raise any unexpected I/O errors. If an
[82] Fix | Delete
# I/O error occurs while PStore is writing to its file, then the file will
[83] Fix | Delete
# become corrupted.
[84] Fix | Delete
#
[85] Fix | Delete
# You can prevent this by setting <em>pstore.ultra_safe = true</em>.
[86] Fix | Delete
# However, this results in a minor performance loss, and only works on platforms
[87] Fix | Delete
# that support atomic file renames. Please consult the documentation for
[88] Fix | Delete
# +ultra_safe+ for details.
[89] Fix | Delete
#
[90] Fix | Delete
# Needless to say, if you're storing valuable data with PStore, then you should
[91] Fix | Delete
# backup the PStore files from time to time.
[92] Fix | Delete
class PStore
[93] Fix | Delete
RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
[94] Fix | Delete
RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
[95] Fix | Delete
WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
[96] Fix | Delete
[97] Fix | Delete
# The error type thrown by all PStore methods.
[98] Fix | Delete
class Error < StandardError
[99] Fix | Delete
end
[100] Fix | Delete
[101] Fix | Delete
# Whether PStore should do its best to prevent file corruptions, even when under
[102] Fix | Delete
# unlikely-to-occur error conditions such as out-of-space conditions and other
[103] Fix | Delete
# unusual OS filesystem errors. Setting this flag comes at the price in the form
[104] Fix | Delete
# of a performance loss.
[105] Fix | Delete
#
[106] Fix | Delete
# This flag only has effect on platforms on which file renames are atomic (e.g.
[107] Fix | Delete
# all POSIX platforms: Linux, MacOS X, FreeBSD, etc). The default value is false.
[108] Fix | Delete
attr_accessor :ultra_safe
[109] Fix | Delete
[110] Fix | Delete
#
[111] Fix | Delete
# To construct a PStore object, pass in the _file_ path where you would like
[112] Fix | Delete
# the data to be stored.
[113] Fix | Delete
#
[114] Fix | Delete
# PStore objects are always reentrant. But if _thread_safe_ is set to true,
[115] Fix | Delete
# then it will become thread-safe at the cost of a minor performance hit.
[116] Fix | Delete
#
[117] Fix | Delete
def initialize(file, thread_safe = false)
[118] Fix | Delete
dir = File::dirname(file)
[119] Fix | Delete
unless File::directory? dir
[120] Fix | Delete
raise PStore::Error, format("directory %s does not exist", dir)
[121] Fix | Delete
end
[122] Fix | Delete
if File::exist? file and not File::readable? file
[123] Fix | Delete
raise PStore::Error, format("file %s not readable", file)
[124] Fix | Delete
end
[125] Fix | Delete
@filename = file
[126] Fix | Delete
@abort = false
[127] Fix | Delete
@ultra_safe = false
[128] Fix | Delete
@thread_safe = thread_safe
[129] Fix | Delete
@lock = Thread::Mutex.new
[130] Fix | Delete
end
[131] Fix | Delete
[132] Fix | Delete
# Raises PStore::Error if the calling code is not in a PStore#transaction.
[133] Fix | Delete
def in_transaction
[134] Fix | Delete
raise PStore::Error, "not in transaction" unless @lock.locked?
[135] Fix | Delete
end
[136] Fix | Delete
#
[137] Fix | Delete
# Raises PStore::Error if the calling code is not in a PStore#transaction or
[138] Fix | Delete
# if the code is in a read-only PStore#transaction.
[139] Fix | Delete
#
[140] Fix | Delete
def in_transaction_wr
[141] Fix | Delete
in_transaction
[142] Fix | Delete
raise PStore::Error, "in read-only transaction" if @rdonly
[143] Fix | Delete
end
[144] Fix | Delete
private :in_transaction, :in_transaction_wr
[145] Fix | Delete
[146] Fix | Delete
#
[147] Fix | Delete
# Retrieves a value from the PStore file data, by _name_. The hierarchy of
[148] Fix | Delete
# Ruby objects stored under that root _name_ will be returned.
[149] Fix | Delete
#
[150] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[151] Fix | Delete
# raise PStore::Error if called at any other time.
[152] Fix | Delete
#
[153] Fix | Delete
def [](name)
[154] Fix | Delete
in_transaction
[155] Fix | Delete
@table[name]
[156] Fix | Delete
end
[157] Fix | Delete
#
[158] Fix | Delete
# This method is just like PStore#[], save that you may also provide a
[159] Fix | Delete
# _default_ value for the object. In the event the specified _name_ is not
[160] Fix | Delete
# found in the data store, your _default_ will be returned instead. If you do
[161] Fix | Delete
# not specify a default, PStore::Error will be raised if the object is not
[162] Fix | Delete
# found.
[163] Fix | Delete
#
[164] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[165] Fix | Delete
# raise PStore::Error if called at any other time.
[166] Fix | Delete
#
[167] Fix | Delete
def fetch(name, default=PStore::Error)
[168] Fix | Delete
in_transaction
[169] Fix | Delete
unless @table.key? name
[170] Fix | Delete
if default == PStore::Error
[171] Fix | Delete
raise PStore::Error, format("undefined root name `%s'", name)
[172] Fix | Delete
else
[173] Fix | Delete
return default
[174] Fix | Delete
end
[175] Fix | Delete
end
[176] Fix | Delete
@table[name]
[177] Fix | Delete
end
[178] Fix | Delete
#
[179] Fix | Delete
# Stores an individual Ruby object or a hierarchy of Ruby objects in the data
[180] Fix | Delete
# store file under the root _name_. Assigning to a _name_ already in the data
[181] Fix | Delete
# store clobbers the old data.
[182] Fix | Delete
#
[183] Fix | Delete
# == Example:
[184] Fix | Delete
#
[185] Fix | Delete
# require "pstore"
[186] Fix | Delete
#
[187] Fix | Delete
# store = PStore.new("data_file.pstore")
[188] Fix | Delete
# store.transaction do # begin transaction
[189] Fix | Delete
# # load some data into the store...
[190] Fix | Delete
# store[:single_object] = "My data..."
[191] Fix | Delete
# store[:obj_hierarchy] = { "Kev Jackson" => ["rational.rb", "pstore.rb"],
[192] Fix | Delete
# "James Gray" => ["erb.rb", "pstore.rb"] }
[193] Fix | Delete
# end # commit changes to data store file
[194] Fix | Delete
#
[195] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction and it cannot
[196] Fix | Delete
# be read-only. It will raise PStore::Error if called at any other time.
[197] Fix | Delete
#
[198] Fix | Delete
def []=(name, value)
[199] Fix | Delete
in_transaction_wr
[200] Fix | Delete
@table[name] = value
[201] Fix | Delete
end
[202] Fix | Delete
#
[203] Fix | Delete
# Removes an object hierarchy from the data store, by _name_.
[204] Fix | Delete
#
[205] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction and it cannot
[206] Fix | Delete
# be read-only. It will raise PStore::Error if called at any other time.
[207] Fix | Delete
#
[208] Fix | Delete
def delete(name)
[209] Fix | Delete
in_transaction_wr
[210] Fix | Delete
@table.delete name
[211] Fix | Delete
end
[212] Fix | Delete
[213] Fix | Delete
#
[214] Fix | Delete
# Returns the names of all object hierarchies currently in the store.
[215] Fix | Delete
#
[216] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[217] Fix | Delete
# raise PStore::Error if called at any other time.
[218] Fix | Delete
#
[219] Fix | Delete
def roots
[220] Fix | Delete
in_transaction
[221] Fix | Delete
@table.keys
[222] Fix | Delete
end
[223] Fix | Delete
#
[224] Fix | Delete
# Returns true if the supplied _name_ is currently in the data store.
[225] Fix | Delete
#
[226] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[227] Fix | Delete
# raise PStore::Error if called at any other time.
[228] Fix | Delete
#
[229] Fix | Delete
def root?(name)
[230] Fix | Delete
in_transaction
[231] Fix | Delete
@table.key? name
[232] Fix | Delete
end
[233] Fix | Delete
# Returns the path to the data store file.
[234] Fix | Delete
def path
[235] Fix | Delete
@filename
[236] Fix | Delete
end
[237] Fix | Delete
[238] Fix | Delete
#
[239] Fix | Delete
# Ends the current PStore#transaction, committing any changes to the data
[240] Fix | Delete
# store immediately.
[241] Fix | Delete
#
[242] Fix | Delete
# == Example:
[243] Fix | Delete
#
[244] Fix | Delete
# require "pstore"
[245] Fix | Delete
#
[246] Fix | Delete
# store = PStore.new("data_file.pstore")
[247] Fix | Delete
# store.transaction do # begin transaction
[248] Fix | Delete
# # load some data into the store...
[249] Fix | Delete
# store[:one] = 1
[250] Fix | Delete
# store[:two] = 2
[251] Fix | Delete
#
[252] Fix | Delete
# store.commit # end transaction here, committing changes
[253] Fix | Delete
#
[254] Fix | Delete
# store[:three] = 3 # this change is never reached
[255] Fix | Delete
# end
[256] Fix | Delete
#
[257] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[258] Fix | Delete
# raise PStore::Error if called at any other time.
[259] Fix | Delete
#
[260] Fix | Delete
def commit
[261] Fix | Delete
in_transaction
[262] Fix | Delete
@abort = false
[263] Fix | Delete
throw :pstore_abort_transaction
[264] Fix | Delete
end
[265] Fix | Delete
#
[266] Fix | Delete
# Ends the current PStore#transaction, discarding any changes to the data
[267] Fix | Delete
# store.
[268] Fix | Delete
#
[269] Fix | Delete
# == Example:
[270] Fix | Delete
#
[271] Fix | Delete
# require "pstore"
[272] Fix | Delete
#
[273] Fix | Delete
# store = PStore.new("data_file.pstore")
[274] Fix | Delete
# store.transaction do # begin transaction
[275] Fix | Delete
# store[:one] = 1 # this change is not applied, see below...
[276] Fix | Delete
# store[:two] = 2 # this change is not applied, see below...
[277] Fix | Delete
#
[278] Fix | Delete
# store.abort # end transaction here, discard all changes
[279] Fix | Delete
#
[280] Fix | Delete
# store[:three] = 3 # this change is never reached
[281] Fix | Delete
# end
[282] Fix | Delete
#
[283] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[284] Fix | Delete
# raise PStore::Error if called at any other time.
[285] Fix | Delete
#
[286] Fix | Delete
def abort
[287] Fix | Delete
in_transaction
[288] Fix | Delete
@abort = true
[289] Fix | Delete
throw :pstore_abort_transaction
[290] Fix | Delete
end
[291] Fix | Delete
[292] Fix | Delete
#
[293] Fix | Delete
# Opens a new transaction for the data store. Code executed inside a block
[294] Fix | Delete
# passed to this method may read and write data to and from the data store
[295] Fix | Delete
# file.
[296] Fix | Delete
#
[297] Fix | Delete
# At the end of the block, changes are committed to the data store
[298] Fix | Delete
# automatically. You may exit the transaction early with a call to either
[299] Fix | Delete
# PStore#commit or PStore#abort. See those methods for details about how
[300] Fix | Delete
# changes are handled. Raising an uncaught Exception in the block is
[301] Fix | Delete
# equivalent to calling PStore#abort.
[302] Fix | Delete
#
[303] Fix | Delete
# If _read_only_ is set to +true+, you will only be allowed to read from the
[304] Fix | Delete
# data store during the transaction and any attempts to change the data will
[305] Fix | Delete
# raise a PStore::Error.
[306] Fix | Delete
#
[307] Fix | Delete
# Note that PStore does not support nested transactions.
[308] Fix | Delete
#
[309] Fix | Delete
def transaction(read_only = false) # :yields: pstore
[310] Fix | Delete
value = nil
[311] Fix | Delete
if !@thread_safe
[312] Fix | Delete
raise PStore::Error, "nested transaction" unless @lock.try_lock
[313] Fix | Delete
else
[314] Fix | Delete
begin
[315] Fix | Delete
@lock.lock
[316] Fix | Delete
rescue ThreadError
[317] Fix | Delete
raise PStore::Error, "nested transaction"
[318] Fix | Delete
end
[319] Fix | Delete
end
[320] Fix | Delete
begin
[321] Fix | Delete
@rdonly = read_only
[322] Fix | Delete
@abort = false
[323] Fix | Delete
file = open_and_lock_file(@filename, read_only)
[324] Fix | Delete
if file
[325] Fix | Delete
begin
[326] Fix | Delete
@table, checksum, original_data_size = load_data(file, read_only)
[327] Fix | Delete
[328] Fix | Delete
catch(:pstore_abort_transaction) do
[329] Fix | Delete
value = yield(self)
[330] Fix | Delete
end
[331] Fix | Delete
[332] Fix | Delete
if !@abort && !read_only
[333] Fix | Delete
save_data(checksum, original_data_size, file)
[334] Fix | Delete
end
[335] Fix | Delete
ensure
[336] Fix | Delete
file.close
[337] Fix | Delete
end
[338] Fix | Delete
else
[339] Fix | Delete
# This can only occur if read_only == true.
[340] Fix | Delete
@table = {}
[341] Fix | Delete
catch(:pstore_abort_transaction) do
[342] Fix | Delete
value = yield(self)
[343] Fix | Delete
end
[344] Fix | Delete
end
[345] Fix | Delete
ensure
[346] Fix | Delete
@lock.unlock
[347] Fix | Delete
end
[348] Fix | Delete
value
[349] Fix | Delete
end
[350] Fix | Delete
[351] Fix | Delete
private
[352] Fix | Delete
# Constant for relieving Ruby's garbage collector.
[353] Fix | Delete
CHECKSUM_ALGO = %w[SHA512 SHA384 SHA256 SHA1 RMD160 MD5].each do |algo|
[354] Fix | Delete
begin
[355] Fix | Delete
break Digest(algo)
[356] Fix | Delete
rescue LoadError
[357] Fix | Delete
end
[358] Fix | Delete
end
[359] Fix | Delete
EMPTY_STRING = ""
[360] Fix | Delete
EMPTY_MARSHAL_DATA = Marshal.dump({})
[361] Fix | Delete
EMPTY_MARSHAL_CHECKSUM = CHECKSUM_ALGO.digest(EMPTY_MARSHAL_DATA)
[362] Fix | Delete
[363] Fix | Delete
#
[364] Fix | Delete
# Open the specified filename (either in read-only mode or in
[365] Fix | Delete
# read-write mode) and lock it for reading or writing.
[366] Fix | Delete
#
[367] Fix | Delete
# The opened File object will be returned. If _read_only_ is true,
[368] Fix | Delete
# and the file does not exist, then nil will be returned.
[369] Fix | Delete
#
[370] Fix | Delete
# All exceptions are propagated.
[371] Fix | Delete
#
[372] Fix | Delete
def open_and_lock_file(filename, read_only)
[373] Fix | Delete
if read_only
[374] Fix | Delete
begin
[375] Fix | Delete
file = File.new(filename, RD_ACCESS)
[376] Fix | Delete
begin
[377] Fix | Delete
file.flock(File::LOCK_SH)
[378] Fix | Delete
return file
[379] Fix | Delete
rescue
[380] Fix | Delete
file.close
[381] Fix | Delete
raise
[382] Fix | Delete
end
[383] Fix | Delete
rescue Errno::ENOENT
[384] Fix | Delete
return nil
[385] Fix | Delete
end
[386] Fix | Delete
else
[387] Fix | Delete
file = File.new(filename, RDWR_ACCESS)
[388] Fix | Delete
file.flock(File::LOCK_EX)
[389] Fix | Delete
return file
[390] Fix | Delete
end
[391] Fix | Delete
end
[392] Fix | Delete
[393] Fix | Delete
# Load the given PStore file.
[394] Fix | Delete
# If +read_only+ is true, the unmarshalled Hash will be returned.
[395] Fix | Delete
# If +read_only+ is false, a 3-tuple will be returned: the unmarshalled
[396] Fix | Delete
# Hash, a checksum of the data, and the size of the data.
[397] Fix | Delete
def load_data(file, read_only)
[398] Fix | Delete
if read_only
[399] Fix | Delete
begin
[400] Fix | Delete
table = load(file)
[401] Fix | Delete
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
[402] Fix | Delete
rescue EOFError
[403] Fix | Delete
# This seems to be a newly-created file.
[404] Fix | Delete
table = {}
[405] Fix | Delete
end
[406] Fix | Delete
table
[407] Fix | Delete
else
[408] Fix | Delete
data = file.read
[409] Fix | Delete
if data.empty?
[410] Fix | Delete
# This seems to be a newly-created file.
[411] Fix | Delete
table = {}
[412] Fix | Delete
checksum = empty_marshal_checksum
[413] Fix | Delete
size = empty_marshal_data.bytesize
[414] Fix | Delete
else
[415] Fix | Delete
table = load(data)
[416] Fix | Delete
checksum = CHECKSUM_ALGO.digest(data)
[417] Fix | Delete
size = data.bytesize
[418] Fix | Delete
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
[419] Fix | Delete
end
[420] Fix | Delete
data.replace(EMPTY_STRING)
[421] Fix | Delete
[table, checksum, size]
[422] Fix | Delete
end
[423] Fix | Delete
end
[424] Fix | Delete
[425] Fix | Delete
def on_windows?
[426] Fix | Delete
is_windows = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince/
[427] Fix | Delete
self.class.__send__(:define_method, :on_windows?) do
[428] Fix | Delete
is_windows
[429] Fix | Delete
end
[430] Fix | Delete
is_windows
[431] Fix | Delete
end
[432] Fix | Delete
[433] Fix | Delete
def save_data(original_checksum, original_file_size, file)
[434] Fix | Delete
new_data = dump(@table)
[435] Fix | Delete
[436] Fix | Delete
if new_data.bytesize != original_file_size || CHECKSUM_ALGO.digest(new_data) != original_checksum
[437] Fix | Delete
if @ultra_safe && !on_windows?
[438] Fix | Delete
# Windows doesn't support atomic file renames.
[439] Fix | Delete
save_data_with_atomic_file_rename_strategy(new_data, file)
[440] Fix | Delete
else
[441] Fix | Delete
save_data_with_fast_strategy(new_data, file)
[442] Fix | Delete
end
[443] Fix | Delete
end
[444] Fix | Delete
[445] Fix | Delete
new_data.replace(EMPTY_STRING)
[446] Fix | Delete
end
[447] Fix | Delete
[448] Fix | Delete
def save_data_with_atomic_file_rename_strategy(data, file)
[449] Fix | Delete
temp_filename = "#{@filename}.tmp.#{Process.pid}.#{rand 1000000}"
[450] Fix | Delete
temp_file = File.new(temp_filename, WR_ACCESS)
[451] Fix | Delete
begin
[452] Fix | Delete
temp_file.flock(File::LOCK_EX)
[453] Fix | Delete
temp_file.write(data)
[454] Fix | Delete
temp_file.flush
[455] Fix | Delete
File.rename(temp_filename, @filename)
[456] Fix | Delete
rescue
[457] Fix | Delete
File.unlink(temp_file) rescue nil
[458] Fix | Delete
raise
[459] Fix | Delete
ensure
[460] Fix | Delete
temp_file.close
[461] Fix | Delete
end
[462] Fix | Delete
end
[463] Fix | Delete
[464] Fix | Delete
def save_data_with_fast_strategy(data, file)
[465] Fix | Delete
file.rewind
[466] Fix | Delete
file.write(data)
[467] Fix | Delete
file.truncate(data.bytesize)
[468] Fix | Delete
end
[469] Fix | Delete
[470] Fix | Delete
[471] Fix | Delete
# This method is just a wrapped around Marshal.dump
[472] Fix | Delete
# to allow subclass overriding used in YAML::Store.
[473] Fix | Delete
def dump(table) # :nodoc:
[474] Fix | Delete
Marshal::dump(table)
[475] Fix | Delete
end
[476] Fix | Delete
[477] Fix | Delete
# This method is just a wrapped around Marshal.load.
[478] Fix | Delete
# to allow subclass overriding used in YAML::Store.
[479] Fix | Delete
def load(content) # :nodoc:
[480] Fix | Delete
Marshal::load(content)
[481] Fix | Delete
end
[482] Fix | Delete
[483] Fix | Delete
def empty_marshal_data
[484] Fix | Delete
EMPTY_MARSHAL_DATA
[485] Fix | Delete
end
[486] Fix | Delete
def empty_marshal_checksum
[487] Fix | Delete
EMPTY_MARSHAL_CHECKSUM
[488] Fix | Delete
end
[489] Fix | Delete
end
[490] Fix | Delete
[491] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function