Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change permissions of file in Ruby

I have code as follows

 def initialise
   @doc_path =nil
   @user= nil
end
def execute
   oscmd = Common::OsCmd.new
   oscmd.log = @log.info("message")
   File.open("#{@doc_path}/new.doc","w") do |f|
      f.puts "/#{@name}  /people/* "
      File.chmod(0777,"#{@doc_path}/new.doc")
      FileUtils.chown("#{@user}, #{@user}, #{@doc_path}")
   end
end

So my code gets executed by tokenisation from other config file where it has values for doc_path, user

My code is giving error on chown and chmod

like image 415
Angel1403 Avatar asked Mar 28 '14 07:03

Angel1403


1 Answers

Try the below by passing valid user in chown :

def self.execute
   oscmd = Common::OsCmd.new
   oscmd.log = @log.info("message")
   File.open("#{@doc_path}/new.doc","w") do |f|
      f.puts "/#{@name}  /people/* "
      File.chmod(0777,"#{@doc_path}/new.doc")
      FileUtils.chown 'vinod', 'vinod', "#{@doc_path}" 
   end #-- do ends here
end #-- def ends here

chown usage:

http://apidock.com/ruby/FileUtils/chown

like image 113
VDN Avatar answered Oct 04 '22 01:10

VDN