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

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:

add_files.each do | add_file |
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
puts “read:”
puts File.readable?(file_str)
puts “write:”
puts File.writable?(file_str), “r+”) do | the_add_file |

# …


Here’s the result:

$ populate_user_table_migrations_01.rb
-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
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)

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 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! :slight_smile:

I’ve tried various IO combinations, various combinations, etc, and I’ve been googling all morning and part of yesterday.
Thanks in advance!

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 File and IO should be very stable by now. You’d a think, eh? :slight_smile:

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!

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 = ‘/home/din/Projects/DLC/code_ruby/update_users_01.txt’
migrate_user_files = files.readlines
migrate_user_files.each do | user_file_name |
migration = ‘/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