fixed bugs in scanner
This commit is contained in:
parent
ed371f8179
commit
731dabcc6c
17
lib/scan.rb
17
lib/scan.rb
|
@ -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
|
end
|
||||||
album.path = pathentry
|
if moved || album.new_record?
|
||||||
|
album.path = pathentry.sub(APP_CONFIG[:photos_path], '')
|
||||||
album.save! unless debug
|
album.save! unless debug
|
||||||
|
end
|
||||||
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,17 +41,23 @@ 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
|
end
|
||||||
photo.path = pathentry
|
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
|
photo.save! unless debug
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.FullScan(debug = false)
|
def self.FullScan(debug = false)
|
||||||
if debug
|
if debug
|
||||||
|
|
Loading…
Reference in a new issue