Sha256: 4aed345066f2a29013da1466e876e1538a511bd297d9bc3b54799581407a24f4

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require 'reap/task'

#
# File Permissions Task
#
class Reap::Perm < Reap::Task

  task_desc "Normalize ownership and permissions of package files."
  section_required true

  attr_accessor :user, :group, :filemod, :dirmod

  def init
    @user = section['user']
    @group   ||= @user
    @filemod ||= 644
    @dirmod  ||= 755
  end

  def run
    puts "Reap is shelling out work to chmod..."

    # misc
    misc = FileList.new
    misc.include('[A-Z]*')
    misc.exclude('InstalledFiles')
    chmod( misc ) unless misc.empty?

    # lib
    libs = FileList.new
    libs.include('lib/**/*')
    libs.exclude('lib/CVS/**/*')
    libs.include('packages/*/lib/**/*')
    libs.exclude('packages/*/lib/CVS/**/*')
    libs.exclude('packages/CVS/**/*')
    chmod( libs ) unless libs.empty?

    # bin
    bins = FileList.new
    bins.include('bin/**/*')
    bins.exclude('bin/CVS/**/*')
    bins.include('packages/*/bin/**/*')
    bins.exclude('packages/*/bin/CVS/**/*')
    bins.exclude('packages/CVS/**/*')
    chmod( bins, 755 ) unless bins.empty?
  end

  # support functions

  def chmod( file_list, file_mode=644, dir_mode=755 )
    dirs, files = file_list.partition{ |l| File.directory?(l) }
    unless files.empty?
      fstr = '"' + files.join('" "') + '"'
      sh %{chmod #{file_mode} #{fstr}}
    end
    unless dirs.empty?
      fstr = '"' + dirs.join('" "') + '"'
      sh %{chmod #{dir_mode} #{fstr}}
    end
  end

  def run_chown
    puts "NOT YET IMPLEMENTED"
  end
#     def _chown( file_list, user, group )
#       fstr = '"' + file_list.join('" "') + '"'
#       if user
#         if group
#           sh %{chown #{user}.#{group} #{fstr}}
#         else
#           sh %{chown #{user} #{fstr}}
#         end
#       end
#     end

end

#Reap.register( Reap::Perm )

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reap-4.3.1 lib/reap/task/fileperm.rb
reap-4.3.2 lib/reap/task/fileperm.rb