Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set global permissions for all files created by a perl script?

I have a script that runs CPAN::Mini::Inject actions and has an App::Cache. It works fine, but sometimes i need to run it from different user accounts, which is when i run afoul of file permissions, since some files are automatically created with 0740 permissions.

Right now i'm using a crutch of system("chmod -R a+w ."), but i'm not liking that.

Is there a way i can enforce, for the scope of the script, a global file mode of 0777 for all created files?

like image 870
Mithaldu Avatar asked Dec 16 '22 19:12

Mithaldu


1 Answers

You can use the umask built-in to change the default file mode. For instance umask 0 will change the default mode to 0777.

BUT, if files are being created with rights 0740, it probably means that CPAN::Mini::Inject is setting the permissions explicitly and the umask may not do any effect.

In that later case, you will have to dive into the module souce code, look for the place where permissions are set and see if you can overload it in anyway. Another option is to just submit a feature request to the author.

BTW, the CPAN::Mini module accepts a dirmode option to set directory permissions.

like image 164
salva Avatar answered May 12 '23 05:05

salva