The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

cPanel::SyncUtil - Perl extension for creating utilities that work with cpanelsync aware directories

SYNOPSIS

  use cPanel::SyncUtil;

DESCRIPTION

These utility functions can be used to in scripts that create and work with cpanelsync environments.

EXAMPLE

See scripts/cpanelsync_build for a working example that can be used to build cPanel's cPAddon Vendor cpanelsync directory for your website.

EXPORT

None by default, all functions are exportable if you wish:

    use cPanel::SyncUtil qw(_raw_dir);
    
    use cPanel::SyncUtil qw(:all);

FUNCTIONS

build_cpanelsync

Builds the .cpanelsync database for the given directory. Arguments are a directory (required) and a boolean to turn on verbose output.

compress_files

Creates the compressed files for the given directory. Arguments are a directory (required) and a boolean to turn on verbose output.

If no .cpanelsync database is located then build_cpanelsync will be called prior to compressing and files.

_chown_pwd_recursively

Takes as its first argument a user that matches ^\w+$ (and optionally a group as its second argument, also matching ^\w+$) and recursively chown's the current working directory to the given user (and group if given).

Currently the return value is from a system() call to chown.

get_files_from_cpanelsync

Returns an array (array ref in scalar context) of files in a given cpanelsync file. If none is passed it uses the one in the current directory.

bzip_file

Creates the .bz2 version of the given file. A second boolean argument can be passed for verbosity. Returns true if it worked false otherwise.

_read_dir_recursively

Returns an array (array ref in scalar context ) of all files recursively in the given directory.

_chown_recursively()

Like _chown_pwd_recursively but takes a third argument of the path to process.

It can take 2 args : 'user, dir' or 3 args: 'user, group, dir'

_safe_cpsync_dir

Returns true if the given argument is a directory that it is safe to be cpanelsync'ified.

See the simple, scripts/cpanelsync_build_dir script for example useage while recursing directories.

_raw_dir

This function makes the .tar and .bz2 version of the file system.

Its arguments are the following:

   _raw_dir($base, $archive, $verbose, @files);

$base and $archive are the only required arguments.

$archive is a directory in $base.

It will chdir in $base and the process the directory $archive

If $verbose is true, output will be verbose.

If @files is specified each item in it is also processed.

Each item in @files must be a file (-f) in $base/$archive.

If it returns false the error is in $!

    _raw_dir($base, $archive, $verbose, @files) 
        or Carp::croak "_raw_dir($base, $archive, $verbose, @files) failed: $!";

Its very important to check the return value because if its failed its possible you will not be in the directory you think and then subsequent file operations will either fail or not work like you expect. Plus if its returned false then there is either a file system problem or the input to the function is not valid. In other words, if it fails you need to resolve the problem before continuing so croaking()ing is a good idea generally.

_sync_touchlock_pwd is then run on $base/$archive so that its now a cpanelsync directory

_get_opts_hash

Shortcut to get a hash (in array context) or hash ref (in scalar context) of the script using this module's command line options.

Takes the same exact input as Getopt::Std getopts()

_sync_touchlock_pwd

Creates the .cpanelsync file (and its .bz2 version) and .cpanelsync.lock for the current working directory

_read_dir

Shortcut to File::Slurp's read_dir

_write_file

Shortcut to File::Slurp's write_file

_lock

Locks the given directories.

    _lock(qw(foo bar baz));

_unlock

Unlocks the given directories.

    _unlock(qw(foo bar baz));

SEE ALSO

cPanel, http://www.cpanel.net

TODO

replace system() calls with perl versions.

anything mentioned in the source

AUTHOR

Daniel Muey, http://drmuey.com/cpan_contact.pl

COPYRIGHT AND LICENSE

Copyright (C) 2006 cPanel, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.