Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not a directory error on Linux in development (eager_loading issue) #37011

Closed
krismichalski opened this issue Aug 22, 2019 · 1 comment · Fixed by #37102
Closed

Not a directory error on Linux in development (eager_loading issue) #37011

krismichalski opened this issue Aug 22, 2019 · 1 comment · Fixed by #37102
Labels

Comments

@krismichalski
Copy link

I wanted to have a README.md file in rails /app directory explaining the code architecture and so on, but I found that it's causing a problem on linux machines in development. Problem does not occur on other environments that use linux or on MacOS.

I'm getting a not a directory error for app/README.md file.

Steps to reproduce

rails new test_app
cd test_app
cp README.md app/
rails s

The same steps reproduced with rails 5.2.3 give the expected behavior.
Reverting this line change also gives the expected behavior.

Expected behavior

  • Rails server should start

Actual behavior

  • Error: Not a directory @ dir_initialize - [test_app root]/app/README.md (Errno::ENOTDIR)
  • Rails server not started

System configuration

Rails version: 6.0.0

Ruby version: 2.6.3

System: Ubuntu 18.04 / Linux Mint 19.1

Workaround

In config/application.rb:

    if Rails.env.development? && Listen::Adapter::Linux.usable?
      path_rejector = ->(path) { path.include?("app/README.md") }
      config.eager_load_paths = config.eager_load_paths.reject(&path_rejector)
    end
@y-yagi y-yagi added the railties label Sep 1, 2019
y-yagi added a commit to y-yagi/rails that referenced this issue Sep 2, 2019
Currently, autoload paths pass to the watcher as directories. If using evented
watcher, this possibly pass as it is to `Listen`.
But autoload paths include files and `Listen` raise an error when was passed
file. So, it is necessary to classify files and directories correctly.

Fixes rails#37011.
@fxn
Copy link
Member

fxn commented Nov 21, 2022

The problem here, really, is that app/README.md should not be in the autoload paths in the first place. Autoload paths should be directories, they represent Object. I suspect the code that initializes them is too permisive and not filtering out files was an overlook.

The patch that addreesed this issue processes files in ActiveSupport::Dependencies.autoload_paths and makes them watchable. However, you don't really want to watch app/README.md, don't you. Editing that file should not trigger a reload.

In Rails 7.1 the fix is going to be different. The new code iterates over Rails.autoloaders.main.dirs, which has only directories.

aeroastro added a commit to aeroastro/rails that referenced this issue Jan 11, 2024
Previously, the Rails application would reload due to changes
in files outside the autoreload paths.
For instance, editing `app/README.md` would trigger a reload,
even though the reloaded classes and modules were identical
to those loaded previously.

This commit fixes this issue by ensuring the application reloads correctly
according to `Rails.autoloaders.main.dirs`, thereby preventing unnecessary reloads.

rails#37011 (comment)
aeroastro added a commit to aeroastro/rails that referenced this issue Jan 11, 2024
Previously, the Rails application would reload due to changes
in files outside the autoload paths.
For instance, editing `app/README.md` would trigger a reload,
even though the reloaded classes and modules were identical
to those loaded previously.

This commit fixes this issue by ensuring the application reloads correctly
according to `Rails.autoloaders.main.dirs`, thereby preventing unnecessary reloads.

rails#37011 (comment)
aeroastro added a commit to aeroastro/rails that referenced this issue Jan 11, 2024
Previously, the Rails application would reload due to changes
in some files outside the autoload paths.
For instance, editing `app/README.md` would trigger a reload,
even though the reloaded classes and modules were identical
to those loaded previously.

This commit fixes this issue by ensuring the application reloads correctly
according to `Rails.autoloaders.main.dirs`, thereby preventing unnecessary reloads.

rails#37011 (comment)
aeroastro added a commit to aeroastro/rails that referenced this issue Jan 11, 2024
Previously, the Rails application would reload due to changes
in some files outside the autoload paths.
For instance, editing `app/README.md` would trigger a reload,
even though the reloaded classes and modules were identical
to those loaded previously.

This commit fixes this issue by ensuring the application reloads correctly
according to `Rails.autoloaders.main.dirs`, thereby preventing unnecessary reloads.

rails#37011 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants