John
John

Reputation: 9456

Building Rails 3 Engine Throwing Gem::Package::TooLongFileName Error

I'm trying to build my engine using gem build myengine but I keep getting the following error:

ERROR:  While executing gem ... (Gem::Package::TooLongFileName)
    Gem::Package::TooLongFileName

I wouldn't expect myengine not to be too long of a name. Any idea what might be going on here?

Upvotes: 4

Views: 1343

Answers (3)

John
John

Reputation: 9456

I solved this issue by finding the exact file that was causing the issue - it was a migration file with a long name.

For those who are interested, the error is thrown from the split_name method of TarWriter class of the rubygems source code. This error will bet thrown if:

  1. The relative path of a file, include the file name itself, is greater than 256 characters
  2. The file name is greater than 100 characters
  3. The file prefix is greater than 155 characters

I hope this helps. I've attached the source code for the split_name method below for review.

def split_name(name) # :nodoc:
  raise Gem::Package::TooLongFileName if name.size > 256

  if name.size <= 100 then
    prefix = ""
  else
    parts = name.split(/\//)
    newname = parts.pop
    nxt = ""

    loop do
      nxt = parts.pop
      break if newname.size + 1 + nxt.size > 100
      newname = nxt + "/" + newname
    end

    prefix = (parts + [nxt]).join "/"
    name = newname

    if name.size > 100 or prefix.size > 155 then
      raise Gem::Package::TooLongFileName
    end
  end

  return name, prefix
end

Upvotes: 9

Christophe Belpaire
Christophe Belpaire

Reputation: 317

I had the same problem and solved it by removing the test/dummy/tmp folder and .sass_cache folder, because they contains long file names

Upvotes: 1

marco
marco

Reputation: 98

I solved this Problem by updateing rubygems to 1.8.25 (gem update --system)

-edit-

check your project.gemspec file: comment out

s.files = ... or s.test_files = ...

if there is any file in your project with a name too long

Upvotes: 4

Related Questions