diff options
author | Chris Schlaeger <chris@linux.com> | 2016-01-18 00:46:21 +0100 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2016-01-18 00:46:21 +0100 |
commit | fefca0e2a692cb8f296a105ac363ec5675b5d8f7 (patch) | |
tree | f15538386a188fa85457ddb6f0ccb41b10ec7404 /lib | |
parent | f3108e6147f92bf8f063b6681bd28eae6ced823a (diff) | |
download | postrunner-fefca0e2a692cb8f296a105ac363ec5675b5d8f7.zip |
FIX: Probably import deleted files again if --force is used.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/FFS_Device.rb | 9 | ||||
-rw-r--r-- | lib/postrunner/FitFileStore.rb | 3 | ||||
-rw-r--r-- | lib/postrunner/Main.rb | 23 |
3 files changed, 22 insertions, 13 deletions
diff --git a/lib/postrunner/FFS_Device.rb b/lib/postrunner/FFS_Device.rb index 5cde333..b7483c1 100644 --- a/lib/postrunner/FFS_Device.rb +++ b/lib/postrunner/FFS_Device.rb @@ -25,12 +25,12 @@ module PostRunner po_attr :activities, :monitorings, :short_uid, :long_uid # Create a new FFS_Device object. - # @param cf [PEROBS::ConstructorForm] cf + # @param p [PEROBS::Handle] p # @param short_uid [Fixnum] A random number used a unique ID # @param long_uid [String] A string consisting of the manufacturer and # product name and the serial number. - def initialize(cf, short_uid, long_uid) - super(cf) + def initialize(p, short_uid, long_uid) + super(p) self.short_uid = short_uid self.long_uid = long_uid restore @@ -72,6 +72,7 @@ module PostRunner entity = @store.new(new_entity_class, myself, fit_file_name, fit_entity) else + Log.debug "FIT file #{fit_file_name} has already been imported" # Refuse to replace the file. return nil end @@ -81,6 +82,8 @@ module PostRunner long_uid, type) fq_fit_file_name = File.join(path, File.basename(fit_file_name)) if File.exists?(fq_fit_file_name) && !overwrite + Log.debug "FIT file #{fq_fit_file_name} has already been imported " + + "and deleted" return nil end # Add the new file to the list. diff --git a/lib/postrunner/FitFileStore.rb b/lib/postrunner/FitFileStore.rb index 09bf3ca..5f2d0a6 100644 --- a/lib/postrunner/FitFileStore.rb +++ b/lib/postrunner/FitFileStore.rb @@ -114,7 +114,8 @@ module PostRunner succ.generate_html_report end - Log.info "#{fit_file_name} successfully added to archive" + Log.info "#{File.basename(fit_file_name)} " + + 'has been successfully added to archive' activity end diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb index 0af9a09..f53ba16 100644 --- a/lib/postrunner/Main.rb +++ b/lib/postrunner/Main.rb @@ -43,16 +43,14 @@ module PostRunner create_directory(@db_dir, 'PostRunner data') @db = PEROBS::Store.new(File.join(@db_dir, 'database')) if (errors = @db.check) != 0 - Log.fatal "Postrunner DB is contains #{errors} errors" + Log.fatal "Postrunner database is corrupted: #{errors} errors found" end # Create a hash to store configuration data in the store unless it # exists already. - unless (cfg = @db['config']) - @db['config'] = @db.new(PEROBS::Hash) - end - cfg['unit_system'] = :metric unless cfg['unit_system'] - cfg['html_dir'] = File.join(@db_dir, 'html') unless cfg['html_dir'] - cfg['version'] = VERSION unless cfg['version'] + cfg = (@db['config'] ||= @db.new(PEROBS::Hash)) + cfg['unit_system'] ||= :metric + cfg['html_dir'] ||= File.join(@db_dir, 'html') + cfg['version'] ||= VERSION # We always override the data_dir as the user might have moved the data # directory. The only reason we store it in the DB is to have it # available throught the application. @@ -513,13 +511,20 @@ EOT create_directory(old_fit_dir, 'Old Fit') cfg = RuntimeConfig.new(@db_dir) - ActivitiesDB.new(@db_dir, cfg).activities.each do |activity| + activities = ActivitiesDB.new(@db_dir, cfg).activities + # Ensure that activities are sorted from earliest to last to properly + # recognize the personal records during import. + activities.sort! { |a1, a2| a1.timestamp <=> a2.timestamp } + activities.each do |activity| file_name = File.join(@db_dir, 'fit', activity.fit_file) next unless File.exists?(file_name) Log.info "Converting #{activity.fit_file} to new DB format" @db.transaction do - new_activity = @ffs.add_fit_file(file_name) + unless (new_activity = @ffs.add_fit_file(file_name)) + Log.warn "Cannot convert #{file_name} to new database format" + next + end new_activity.sport = activity.sport new_activity.sub_sport = activity.sub_sport new_activity.name = activity.name |