简体   繁体   中英

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 command.

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

Perhaps the directory does not exist. Remember the difference between:

empty_directory 'app/assets/stylesheets/material_ui'
empty directory '/app/assets/stylesheets/material_ui'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM