Class: PStore

Inherits:
Object show all
Defined in:
lib/tdiary/compatible.rb

Instance Method Summary collapse

Instance Method Details

#compatible_transaction_originalObject



30
# File 'lib/tdiary/compatible.rb', line 30

alias compatible_transaction_original transaction

#transaction(*args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tdiary/compatible.rb', line 31

def transaction(*args, &block)
	begin
		compatible_transaction_original(*args, &block)
	rescue PStoreRuby18Exception
		# first loaded the pstore file (it's created by Ruby-1.8)
		# force convert ASCII_8BIT pstore data to UTF_8
		file = open_and_lock_file(@filename, false)
		table = Marshal::load(file, proc {|obj|
			if obj.respond_to?('force_encoding') && obj.encoding == Encoding::ASCII_8BIT
				obj.force_encoding('UTF-8')
			end
			obj
		})
		table[:__ruby_version] = RUBY_VERSION
		if on_windows?
			save_data_with_fast_strategy(Marshal::dump(table), file)
		else
			save_data_with_atomic_file_rename_strategy(Marshal::dump(table), file)
		end
		retry
	end
end