Git Product home page Git Product logo

fileutils-1's Introduction

Description

This cookbook provides the fileutils resource. The resource can be used to set attributes on all of the files in a directory and subdirectory. We've had years of people complaining that the directory recursive mode, which is in fact a parent operation, does not work on subdirectories and files. In this cookbook recursive refers to subdirectories and the files contained inside them.

Requirements

Developed for RHEL and Solaris servers.

Resource Parameters

The fileutils resource will accept two actions.

  • :change is used to modify ownership and permission mode bit settings.
  • :delete is used to remove files and directories. :delete always functions in a recursive mode.
Action Parameter Use
:change path Specify the starting path or file. The path must exist for anything to be done.
owner Set the owner of the files and directories to this value.
group Set the group of the files and directories to this value.
file_mode Set the permission mode for files. Specify octal numbers or mode change symbols
directory_mode Set the permission mode for directories. Specify octal numbers or mode change symbols
recursive Boolean. Use top down traversal from the starting path. Default is true. When recursive is false only the initial directory and contents are changed.
only_files Boolean. Only change files. Default is false.
only_directories Boolean. Only change directories. Default is false.
pattern Regex. Match to filter the basename of files and directories.
follow_symlink Boolean. Continue on past symlinks. Very dangerous option with a high risk of changing unintended files. Default is false!
quiet Boolean. Suppress output for changing each file. Default is false.
Action Parameter Use
:delete path Specify the starting path or file.
recursive Delete always functions in recursive mode.
only_files Boolean. Only delete files. Default is false.
pattern Regex. Match to filter the basename of files and directories.
follow_symlink Boolean. Continue on past symlinks. Very dangerous option with a high risk of deleting unintended files. Default is false!
force Boolean. Use the for option with FileUtils.
quiet Boolean. Supress output for deleting each file. Default is false.

Mode bit settings

You may specify the mode as a numeric value.

0o600, 0600, '0600' and 420 will all create the same numeric setting. Note that '600' is treated as decimal 600 and is not the same as '0600' which is treated as octal 600.

You may use symbolic settings. Pick from the who list and add or subtract access permissions. The code tries to mimic the chmod command.

Who

  • u Owning user
  • g Owning group
  • o Others
  • a Everyone

Permissions

  • r Read
  • w Write
  • x Search/execute
  • s Assign user
  • t Sticky bit

Examples

  • '+r' Adds read permissions to all files
  • 'g+r' Adds read permissions for the group to all files
  • 'o-w' Removes write permissions for other from all files

Usage

A good example of why you would use the fileutils resource would be setting attributes on files and directories after directory and file resources have created things. Notice that fileutils and directory resources treat recursive as moving in opposite directions.

# Create some directories
dir '/export/home/my/stuff/deep' do
  recursive true  # creates parents
end

# Set the owner on multiple directories
fileutils '/export/home/my' do # Set the child nodes
  owner 'my'
end

# Empty a directory
fileutils '/export/home/my' do
  action :delete
end

# Set mode attributes
fileutils '/export/home/my' do # Set the child nodes
  file_mode ['o+r', 'g+w']
  directory_mode ['o+rx', 'g+wrx']
end

# Change only the top level directory and it's files
# should not change .../stuff/**
fileutils '/export/home/my' do
  recursive false
  files_only true
  file_mode ['0700']
end

Author

  • Mark Gibbons

Acknowlegments

fileutils-1's People

Contributors

axelrtgs avatar gympee avatar joemillerr avatar markgibbons avatar ramereth avatar xorimabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.