rroblak/seed_dump

Opening file in read/write mode prevents use of /dev/stdout as target, unless it's the terminal

dmolesUC opened this issue · 0 comments

I've been trying to get db:seed:dump to write to $stdout by passing FILE=/dev/stdout. This sort of works, insofar as if I type

FILE=/dev/stdout rake db:seed:dump

in the terminal, I get the seeds dumped to the terminal. However, if I try to pipe the output to grep, redirect it to a file, or otherwise mess with it, it fails with Errno:EACCESS.

After some experimentation (see this StackOverflow question), I narrowed the issue down to this line in DumpMethods.open_io:

mode = options[:append] ? 'a+' : 'w+'

Is there a reason we need the + ("update" mode) here? I monkey-patched open_io to use plain w instead and it seems fine.