| Module | Symbiosis::Utils |
| In: |
common/lib/symbiosis/utils.rb
|
This module has a number of useful methods that are used everywhere.
Allow arbitrary parameters in parent_dir to be retrieved.
This function uses the FileUtils mkdir_p command to make a directory. It adds the extra options of :uid and :gid to allow these to be set in one fell swoop.
This has been written to avoid the TOCTTOU race conditions between creating a directory, and chowning it, to make sure that we don‘t accidentally chown a file on the end of a symlink
It returns the name of the directory created.
If a numeric argument is given, it is rounded to the nearest whole number, and returned as an Integer.
If a string is given, the method attempts to parse it. The quota can be a decimal, followed optionally by a space, and optionally by a "prefix". Prefixes it understands are:
* k, M, G, T, P as powers of 10 * ki, Mi, Gi, Ti, Pi as powers of 2.
The answer is given as an Integer.
An argument error is given if the string cannot be parsed, or the argument is neither a Numeric or String object.
This function generates a string of random numbers and letters from the sequence A-Z, a-z, 0-9 minus 0, O, o, 1, I, i, l.
This method opens a file in a safe manner, avoiding symlink attacks and TOCTTOU race conditions.
The mode can be a string or an integer, but must not be "w" or "w+", or have File::TRUNC set, to avoid truncating the file on opening.
opts is an options hash in which the uid, gid, and mode file bits can be specified.
By default mode is set using the current umask.
Records a parameter.
If a file is created, or written to, then the permissions are set such that the file is owned by the same owner/group as the parent_dir, and readable by everyone, but writable only by the owner (0644).
Directories owned by system users/groups will not be written to.
Many of our utility scripts have integrated documentation at their head.
This method will show the manual to the caller.