fixed bugs in scanner

This commit is contained in:
Espen Antonsen 2009-08-11 01:39:27 +02:00
parent ed371f8179
commit 731dabcc6c

View file

@ -16,15 +16,18 @@ module ScanFiles
Dir.entries( path ).each {|entry| Dir.entries( path ).each {|entry|
pathentry = path + "/" + entry pathentry = path + "/" + entry
if File.directory?(pathentry) && !([".", ".."].include?( entry )) if File.directory?(pathentry) && !([".", ".."].include?( entry ))
album = Album.find_by_path( pathentry ) || Album.new() album = Album.find_by_path( pathentry.sub(APP_CONFIG[:photos_path], '') ) || Album.new()
unless entry == entry.parameterize unless entry == entry.parameterize
puts pathentry + " will now be moved to " + path + "/" + entry.parameterize puts pathentry + " will now be moved to " + path + "/" + entry.parameterize
#FileUtils.mv( pathentry, entry.parameterize) #FileUtils.mv( pathentry, entry.parameterize)
File.rename( pathentry, path + "/" + entry.parameterize ) unless debug File.rename( pathentry, path + "/" + entry.parameterize ) unless debug
pathentry = path + "/" + entry.parameterize pathentry = path + "/" + entry.parameterize
moved = true
end
if moved || album.new_record?
album.path = pathentry.sub(APP_CONFIG[:photos_path], '')
album.save! unless debug
end end
album.path = pathentry
album.save! unless debug
self.ScanDirectory(pathentry, debug) self.ScanDirectory(pathentry, debug)
elsif File.file?(pathentry) elsif File.file?(pathentry)
self.ScanFile(pathentry, debug) self.ScanFile(pathentry, debug)
@ -38,16 +41,22 @@ module ScanFiles
return unless [".jpeg", ".jpg", ".gif", ".png"].include?( File.extname(path).downcase ) return unless [".jpeg", ".jpg", ".gif", ".png"].include?( File.extname(path).downcase )
puts "analyze file " + path puts "analyze file " + path
pathentry = path pathentry = path
photo = Photo.find_by_path( path ) || Photo.new() photo = Photo.find_by_path( path.sub(APP_CONFIG[:photos_path], '') ) || Photo.new()
puts "new record " + photo.new_record?.to_s
unless File.basename( path, File.extname(path) ) == File.basename(path, File.extname(path)).parameterize unless File.basename( path, File.extname(path) ) == File.basename(path, File.extname(path)).parameterize
pathentry = File.dirname(path) + "/" + File.basename( path, File.extname(path) ).parameterize + File.extname(path).downcase pathentry = File.dirname(path) + "/" + File.basename( path, File.extname(path) ).parameterize + File.extname(path).downcase
puts path + " will now be moved to " + pathentry puts path + " will now be moved to " + pathentry
#FileUtils.mv( path, File.basename( path, File.extname(path) ).parameterize + File.extname(path).downcase ) #FileUtils.mv( path, File.basename( path, File.extname(path) ).parameterize + File.extname(path).downcase )
#File.move( path, File.dirname(path) + "/" + File.basename( path, File.extname(path) ).parameterize + File.extname(path) ) #File.move( path, File.dirname(path) + "/" + File.basename( path, File.extname(path) ).parameterize + File.extname(path) )
File.rename( path, pathentry ) unless debug File.rename( path, pathentry ) unless debug
moved = true
end
if photo.new_record? || moved
puts "save file"
photo.path = pathentry.sub(APP_CONFIG[:photos_path], '')
photo.album = Album.find_by_path( File.dirname( pathentry ).sub(APP_CONFIG[:photos_path], '') )
photo.save! unless debug
end end
photo.path = pathentry
photo.save! unless debug
end end
def self.FullScan(debug = false) def self.FullScan(debug = false)