當我執行這個程序時,它運行良好,但驗證返回錯誤。如果我重新執行它,驗證將起作用。如何等待寫入文件?
fullpath
是備份的目錄,refpath
是路徑到原始文件:
if (fullpath.include?(refpath) && refpath.empty? == false && fullpath.empty? == false)
diffpath= "#{fullpath} #{refpath}"
puts diffpath
sortie = IO.popen("diff -Bb #{diffpath}").readlines #(fullpath backup_dir)
#puts fullpath
if sortie.empty?
puts "Les fichiers -#{f} sont identiques."
else
puts "Modification : [#{refpath}] \n [#{fullpath}] "
end
end
主要程序是:
require "modif.rb"
require "testdate.rb"
require "restore_data.rb"
#Pour la sauvegarde des fichiers
puts "__________SAUVEGARDE__________"
#Pour la restauration des fichiers :
puts "__________RESTAURATION__________"
#Vérification de l'intégrité des fichiers restaurés.
puts "__________VERIFICATION__________"
sleep(5.0)
v = Verif.new
v.do_verif(outdir)
當我打開該文件的目錄恢復,文件不完全寫入。
在致電驗證之前,我打電話給保存,備份和驗證。
sleep
不起作用。該過程完全暫停,不會寫入丟失的文件。
保存/恢復使用哪些函數來寫入文件? – Taum
我清理你的問題(希望)使其更容易理解。看着你的代碼,我沒有看到任何寫入文件的嘗試。 'IO.popen(「diff -Bb#{diffpath}」)。readlines'可以使用'%x'或反引號更容易地完成。另外,您不需要爲需要的文件使用「.rb」擴展名。如果沒有它,Ruby將自動添加「.rb」擴展名。 –
這可能是相關的:http:// stackoverflow。com/questions/6701103/understanding-ruby-and-os-io-buffering另外,你可能想把你的意見翻譯成英文,因爲不是每個人都在這裏說法語;-) – Taum