Still getting ENOENT error `initialize': No such file or directory @ rb_sysopen

1,213 views
Skip to first unread message

dwilde1

unread,
Jan 21, 2019, 4:27:06 PM1/21/19
to Ruby on Rails: Talk
Hi, folks --

Sorry if this has been discussed ad infinitum but I've been searching and testing for hours and I'm not getting anywhere

My Ruby is ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] on  Ubuntu 18.4

I created a bunch of files using a Rails generator (5.2.2) but since 'rails g' can't utilize all the options a migration file is capable of. I need to change_column and add_column and then re-write the file.

Here's the pertinent part of the modification program:

<code>
add_files.each do | add_file |
    add_file.chomp
    file_str = "/home/din/Projects/DLC/rails_server/product_exchange/db/migrate/" + add_file
    puts "exist"
    puts File.exist?(file_str)
    puts "ls"
    ls_str = "ls -al " + file_str
    system(ls_str)
    puts "read:"
    puts File.readable?(file_str)
    puts "write:"
    puts File.writable?(file_str)
  File.open(file_str, "r+")  do | the_add_file |
# ...
  end
</code>

Here's the result:
<execute>
$ populate_user_table_migrations_01.rb
exist
false
ls
-rw-rw-rw- 1 din din 90 Jan 21 13:11 /home/din/Projects/DLC/rails_server/product_exchange/db/migrate/20190119232341_add_columns_to_alabama_users_table.rb
read:
false
write:
false
Traceback (most recent call last):
    4: from /home/din/Projects/DLC/code_ruby/populate_user_table_migrations_01.rb:5:in `<main>'
    3: from /home/din/Projects/DLC/code_ruby/populate_user_table_migrations_01.rb:5:in `each'
    2: from /home/din/Projects/DLC/code_ruby/populate_user_table_migrations_01.rb:17:in `block in <main>'
    1: from /home/din/Projects/DLC/code_ruby/populate_user_table_migrations_01.rb:17:in `open'
/home/din/Projects/DLC/code_ruby/populate_user_table_migrations_01.rb:17:in `initialize': No such file or directory @ rb_sysopen - /home/din/Projects/DLC/rails_server/product_exchange/db/migrate/20190119232341_add_columns_to_alabama_users_table.rb (Errno::ENOENT)

</execute>

Now, as you can see from the output of the ls -al command, the file is there, and it's readable and writable. The db/migrate directory is also writable by world, but none of the tests find it and it blows up on File.open. I'm running the updater from inside db/migrate, although as you can see the updater now has hard-coded paths everywhere.

Please, somebody tell me this is something trivial and silly! :)

I've tried various IO combinations, various File.open combinations, etc, and I've been googling all morning and part of yesterday.

Thanks in advance!

Colin Law

unread,
Jan 22, 2019, 5:49:33 AM1/22/19
to Ruby on Rails: Talk
On Mon, 21 Jan 2019 at 21:27, dwilde1 <dwi...@gmail.com> wrote:
>
> Now, as you can see from the output of the ls -al command, the file is there, and it's readable and writable. The db/migrate directory is also writable by world, but none of the tests find it and it blows up on File.open. I'm running the updater from inside db/migrate, although as you can see the updater now has hard-coded paths everywhere.

Is it specific to that file or directory? What happens if you try
another file somewhere else?
If it is something specific then try another file in that directory,
and so on till you work out what is going on.
I suppose it could be something like an unprintable character in the
filename or something.

Colin

dwilde1

unread,
Jan 22, 2019, 11:00:43 AM1/22/19
to Ruby on Rails: Talk
On Tuesday, January 22, 2019 at 3:49:33 AM UTC-7, Colin Law wrote:

Is it specific to that file or directory?  What happens if you try
another file somewhere else?
If it is something specific then try another file in that directory,
and so on till you work out what is going on.
I suppose it could be something like an unprintable character in the
filename or something.

Hi, Colin  --

Actually, it doesn't seem to be specific. I'm using a Ruby program that creates fifty sets of files (for each state in US), and then updating those files with better column definitions. Ubuntu did just force my Rails to update to bleeding edge, so it is possible that something has been introduced but that is unlikely.as File and IO should be very stable by now. You'd a think, eh? :)

Your idea of a stray binary in there is plausible; I don't have a current copy of RubyMine but I can see if BEAV will show me  something useful. Thanks for the idea!

dwilde1

unread,
Jan 22, 2019, 8:02:06 PM1/22/19
to Ruby on Rails: Talk
It's been a decade since I coded Rails (though Ruby much more recently; there is no excuse). Colin, you were right

file_location = '/home/din/Projects/DLC/rails_server/product_exchange/db/migrate/'

files = File.new '/home/din/Projects/DLC/code_ruby/update_users_01.txt'
migrate_user_files = files.readlines
migrate_user_files.each do | user_file_name |
    migration = File.new '/home/din/Projects/DLC/rails_server/product_exchange/db/migrate/' + user_file_name.chomp
# Error was very simple: mystring.chomp returns a new string without the linefeed character    ^^^^^^^^^^^^^^^^^^^^^^
#   I had interpreted it as modify-in-place
    lines = migration.readlines
    lines.each do | l |
        puts "  " + l
    end
end


Reply all
Reply to author
Forward
0 new messages