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

use cPanel::SyncUtil;

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

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

None by default, all functions are exportable if you wish:
use cPanel::SyncUtil qw(_raw_dir);
use cPanel::SyncUtil qw(:all);

Builds the .cpanelsync database for the given directory. Arguments are a directory (required) and a boolean to turn on verbose output.
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.
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.
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.
Creates the .bz2 version of the given file. A second boolean argument can be passed for verbosity. Returns true if it worked false otherwise.
Returns an array (array ref in scalar context ) of all files recursively in the given directory.
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'
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.
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
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()
Creates the .cpanelsync file (and its .bz2 version) and .cpanelsync.lock for the current working directory
Shortcut to File::Slurp's read_dir
Shortcut to File::Slurp's write_file
Locks the given directories.
_lock(qw(foo bar baz));
Unlocks the given directories.
_unlock(qw(foo bar baz));


replace system() calls with perl versions.
anything mentioned in the source

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

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.