- 1 year ago 43
Ruby Question

Thor empty_directory command raises 'permission denied' when cloning from repo in rails composer custom recipe

Today I'm fighting against this:

mkdir': Permission denied @ dir_s_mkdir - /app/assets/stylesheets/material_ui (Errno::EACCES)

I'm creating my own rails composer generator. What I want is clone from my repo some files and put them inside the app I'm generating when I call
rails new etc etc...
. The generator works well (it clones a lot of files, it even unzips a big font folder!) and all the recipes do their work except one.

This one contains (among others) this line

empty_directory '/app/assets/stylesheets/material_ui'

This Thor action fails saying 'permission denied'.

Of course I cannot CHMOD anything before, because there is not any folder until I launch the
rails new

How can I create a directory in a rails composer recipe using Thor?

Answer Source

I have found the solution. Is so simply to be silly, but as I've found other people stumbling against this mistake, I'll answer my own question as documentation.

The fail is in the path.

empty_directory '/app/assets/stylesheets/material_ui'

is not the same of

empty_directory 'app/assets/stylesheets/material_ui'

The second one is the right one because is the absolute path, of the generated application.

The first one, as it starts with / is interpreted as a subfolder of the recipe execution point, and, as it doesn't exists, it raises a permission error.