blackwinter / ruby-filemagic

Ruby bindings to the magic(4) library, revised.
https://blackwinter.github.iom/ruby-filemagic
146 stars 34 forks source link

problem with filename to long error #20

Closed NVD-R closed 8 years ago

NVD-R commented 8 years ago

hi, i get error about filename to long and i search about it but i cant find any thing.can you help me about how can i handled this error?

FileMagic::FileMagicError: failed lookup: cannot open 'دریاچه_ی_چیتگر_یا_شهدای_خلیج_فارس_بزرگترین_دریاچه_ی_مصنوعی_ایران_است_که_در_شمال_غرب_شهر_تهران_واقع_شده_و_در_کنار_این_دریاچه_پارک_جنگلی_چیتگر_قرار_گرفته_است.docx' (File name too long)

blackwinter commented 8 years ago

Can you please provide more information:

NVD-R commented 8 years ago
  1. ruby 1.9.3p484 (2013-11-22 revision 43786)
  2. `def self.verifier @verifier ||= ActiveSupport::MessageVerifier.new(Config[:verifier_key]) end

    def self.text?(filename) begin fm = FileMagic.new(FileMagic::MAGIC_MIME) fm.file(filename) =~ /^text\// ensure fm.close end end

    def self.binary?(filename) !text?(filename) end`

  3. 'ruby-filemagic', '0.7.1'
blackwinter commented 8 years ago

I cannot reproduce the error, but I'm almost certain this has nothing to do with ruby-filemagic, anyway. What does file --mime <your-long-file-name> say? (You might need to install the file utility first.)

NVD-R commented 8 years ago

file: text/plain; charset=us-ascii

blackwinter commented 8 years ago

Can you try File.open(filename) { |f| fm.fd(f) } instead of fm.file(filename)?

NVD-R commented 8 years ago

i use that code but not work !!! does exist any limitation for filename length in FileMagic?

blackwinter commented 8 years ago

i use that code but not work !!!

Please post the exact error message and backtrace.

does exist any limitation for filename length in FileMagic?

No, there's not. My suspicion was that libmagic had a limit; but seeing as the file command worked, we can probably rule that out. [EDIT: The exception is raised here, so the error definitely originates from inside libmagic.]