lib/qooxview/storages/csv.rb in qooxview-1.9.10 vs lib/qooxview/storages/csv.rb in qooxview-1.9.11

- old
+ new

@@ -1,17 +1,17 @@ class CSV < StorageType def configure(config) dputs(3) { "Configuring CSV with #{@name}" } - @csv_dir = 'data/' + @csv_dir = File.join($data_dir, get_config('data', :StorageType, :data_dir)) @add_only = false @backup_count = 5 super config - @csv_backup = "#{@csv_dir}/backup/" + @csv_backup = File.join(@csv_dir, 'backup') @csv_name = "#{@entity.class.name}.csv" - @csv_file = @csv_dir + @csv_name - @csv_backup_file = @csv_backup + @csv_name + @csv_file = File.join(@csv_dir, @csv_name) + @csv_backup_file = File.join(@csv_backup, @csv_name) dputs(5) { "data_file is #{@csv_file}" } @mutex = Mutex.new end @@ -28,19 +28,20 @@ end # Saves the data stored, optionally takes an index to say # which data needs to be saved def save(data) + #dputs_func @add_only ? dputs(5) { "Not saving data for #{@name}" } : @mutex.synchronize { begin dputs(3) { "Saving data for #{@name} to #{@csv_dir} - #{@csv_file}" } [@csv_dir, @csv_backup].each { |d| FileUtils.mkdir_p d unless File.exists? d } - #dputs(5) { "Data is #{data.inspect}" } + dputs(5) { "Data is #{data.inspect}" } if File.exists? @csv_file time = File.mtime(@csv_file).strftime('%Y%m%d_%H%M%S') backup = "#{@csv_backup_file}.#{time}" counter = 1 @@ -63,10 +64,10 @@ FileUtils.mv tmpfile, @csv_file #%x[ sync ] dputs(3) { 'Delete oldest file(s)' } if (backups = Dir.glob("#{@csv_backup_file}.*").sort).size > @backup_count oldfiles = backups.first(backups.size - @backup_count) - dputs(3){"Deleting #{oldfiles.inspect}"} + dputs(3) { "Deleting #{oldfiles.inspect}" } FileUtils.rm oldfiles end rescue Exception => e dputs(0) { "Error: couldn't save CSV #{@name}" } dputs(0) { "#{e.inspect}" }