2017-08-17 29 views
1

那麼,這是我在一個漫長的時間裏最怪異的文件系統相關問題。文本文件被不完整地移動到cifs與Perl的掛載點

I have a script,基本上連接遠程IMAP服務器上,下載郵件,將其標記爲已讀,敲竹槓的垃圾,只下載.txt.xml文件。如果.txt使用Text::Unaccent刪除重音。

這是在imap遠程文件夾與此服務器上本地安裝的cif文件夾的1對1關係上完成的。刪除imap下載和重音處理工作得很好。

我的問題是:如果我下載文件,處理重音,並將其移到cifs掛載的目錄,該文件被撕掉(最後4到10K丟失)。如果我將它移動到同一臺機器上的anoter分區上,文件會以一種理智的方式移動(相同的md5sum,相同的文件大小,不會被diff注意到)。

的代碼,不會口音刪除和移動文件的塊:

 #If file extension = .txt 
     if ("$temp_dir/$arquivo" =~ /txt$/i){ 

     #Put file line by line inside array 
     open (LEITURA, "$temp_dir/$arquivo"); 
     @manipular = <LEITURA>; 
     close LEITURA; 

     #Open the same file to writing with other filehandler 
     open (ESCRITA, ">", "$temp_dir/$arquivo"); 
     foreach $manipula_linha (@manipular){ 
      # Removes & and accents 
      $manipula_linha =~ s/\&/e/g; 
      $manipula_linha = unac_string("UTF-8", $manipula_linha); 
      print ESCRITA $manipula_linha; 
     }; 
     }; 

     # copy temp file to final destination. If cifs = crash 
     # move also does not work... 
     copy "$temp_dir/$arquivo", "$dest_file"; 
     unlink "$temp_dir/$arquivo"; 

CIFS版本:

[[email protected] mail_downloader]# modinfo cifs 
filename:  /lib/modules/2.6.18-409.el5.centos.plus/kernel/fs/cifs/cifs.ko 
version:  1.60RH 
description: VFS to access servers complying with the SNIA CIFS Specification e.g. Samba and Windows 
license:  GPL 

Perl版本:

[[email protected] mail_downloader]# perl --version 

This is perl, v5.8.8 built for i386-linux-thread-multi 

Unaccent版本:

[[email protected] mail_downloader]# rpm -qa | grep Unaccent 
perl-Text-Unaccent-1.08-1.2.el5.rf 

問題:任何線索爲什麼perl movecopy有這種行爲與CIFS掛載點以及如何解決此問題?

顯然我不能在這裏發佈文件內容,因爲他們是EDI相關的東西,並有一些財務信息。

而且,如果我評論perl的copy處理文件自己unaccent使用cpmv完成後,該文件被正確地移動到cifs掛載點。

回答

0

嗯,我並不自豪這樣做,但它是一種解決方法,幾乎​​可以通過不使用perl來處理此文件移動來消除cifs錯誤。

而不是使用movecopy從Perl,虐待使用操作系統mv二進制通過system函數。

的舊代碼塊:

copy "$temp_dir/$arquivo", "$dest_file"; 
unlink "$temp_dir/$arquivo"; 

核心的新塊:

system("/bin/mv", "$temp_dir/$arquivo", "$dest_file"); 
1

問題是真的很明顯 - 你不關閉文件,一旦你向它寫完。當您將其複製/移動到其他文件系統時,會丟失一塊尚未同步到磁盤的文件。

 open (ESCRITA, ">", "$temp_dir/$arquivo"); 
    foreach $manipula_linha (@manipular){ 
     # Removes & and accents 
     $manipula_linha =~ s/\&/e/g; 
     $manipula_linha = unac_string("UTF-8", $manipula_linha); 
     print ESCRITA $manipula_linha; 
    }; 

    # Flush the file 
    my $old_fh = select(ESCRITA); 
    $| = 1; 
    select($old_fh); 

    close ESCRITA; 
    }; 

    move "$temp_dir/$arquivo", "$dest_file"; 
+0

好吧。對我感到羞恥。爲了測試目的,我在其他腳本上寫了這個不起作用的函數,並且我忘記了將'close ESCRITA'移植到這個函數中。猜猜你是對的。 – nwildner

+0

收到帶有4個'.txt'文件的電子郵件後,問題再次複製。我猜它只與文件關閉無關。沒有關於cifs的'dmesg'消息不可用... – nwildner

+0

問題不在於cifs - 它是本地文件系統緩衝寫入。我期望關閉文件會導致它將內容刷新到磁盤,但它聽起來像需要一些幫助。我已經更新了我的答案,並使用了一個可以工作的文件。 –