NAME

CBAIS::Path::FileLocator - file locator


SYNOPSIS

    use CBAIS::Path::FileLocator;
    my ($fl) = new CBAIS::Path::FileLocator();
    my ($file) = $fl->getSpecificFile('conf', 'Class.cf');
    print "Found file $file\n";


DESCRIPTION

The CBAIS::Path::FileLocator object is used for finding operating system/processor dependent, and host specific versions of files in directory trees. It uses the file naming conventions shown below.

<project>/<directory_root>/[<os><ps>]<os_version><ps><architecture>/<filename>.<specifier>

<specifier> = <fq_hostname>|<hostname>|<domain_name>|<alias>

sp
Path separator string. defaults to '::'. (see CBAIS::Options::PathSeparator)

project
The project being searched. A project is an arbitrary root directory used to group together CBAIS data and configs.

directory_root
Different file types are generally organiased inside directory roots under a given project. e.g. 'conf/Classes', 'copy/classname'.

os
The name of the operating system. This is optional. If enabled, the fallback directory share is appended to the search path.

os_version
The operating system version.

architecture
The architecture.

filename
The file being searched for e.g. 'ClassFile.cf', '/etc/passwd'.

specifier
one of the supported specifiers, hostname, domainname, aliases.


USAGE


    use CBAIS::Util::Utils;
    use CBAIS::Path::FileLocator;
    my ($specifier) = new CBAIS::Path::FileLocator();
    my ($file) = $specifier->getSpecificFile('conf/Classes', 'Class.cf');
    if ($file eq '/cbais/default/conf/Classes/Linux::2.2.16-22::i686/Class.cf')
    {
        print "Found file for Linux 2.2.16-22 and i686\n";
    }
    $file = $specifier->getHostSpecificFile("copy/Class", '/etc/passwd');
    if ($file eq "/cbais/default/copy/Class/etc/passwd.avalon")
    {
        print "Found file for host avalon\n";
    }
    my ($sunos_specifier) = new
       CBAIS::Path::FileLocator(OS => 'Sunos',
                               ARCHITECTURE => 'sun4u',
                               GENERIC_ARCHITECTURE => 'sun4',
                               OS_RELEASE => '5.5',
                               MAJOR_OS_RELEASE => '5.x',
                               PROJECTS => ['project1', 'default', ]);
    $sunos_specifier->getHostArchSpecificFile("pkg/local", 'apache.tgz');
    if ($file eq "test_data/default/pkg/local/Linux::2.2.16-22::i686/apache.tgz.avalon")
    {
        print "Found very very specific file\n";

    }


METHODS

The FileLocator methods are listed below.

new() hash_ref}
creates a new Path Specifier. The hash reference must contain values for the various search path elements. Values which can be passed are
OS
the name of the operating system.

OS_RELEASE
operating system release

MAJOR_OS_RELEASE
Major release (e.g. 5.x)

ARCHITECTURE
architecture of CPU (e.g. sun4u, i686)

GENERIC_ARCHITECTURE
generic architecture type (e.g. sun4, i386)

PROJECTS
list of projects to search in

HOSTNAME
name of host

OS_ENABLED
If set to a true value, enables the OS name in search paths.

enableOSName
enable the OS name in the search path.

disableOSName()
disable the OS name in the search path.

setProjects() project ..
Set the project search list for this FileLocator. Note that the configuration details for a project are sourced from the CBAIS.conf config file.

setArchitecture() architecture
set the architecture. The generic architecture is automatically set.

setOS() os
set the operating system.

setOSRelease() os release
set the operating system release. The major OS release number is automatically set.

toString()
return a string representation of this object.

getSpecificFile() root, file
root
the root to perform the search in.

file
file to search for (maybe be a filepath e.g. '/etc/passwd').

Locate a specific file. The file is specific as far as operating system type and release, and processor type information (i.e. CBAIS dir tree structure) is concerned. File name suffixes are not applied. If no specific files are found (and the file does not exist), 0 is returned, otherwise the most specific file found is returned.

getHostSpecificFile() root, file
root
the root to perform the search in.

file
file to search for.

Locate a host specific file. Only file suffix specifiers are checked in this method. The architecture and OS version specifiers are ignored.

getHostArchSpecificFile() root, file
root
the root to perform the search in.

file
file to search for.

Locate a host specific file. OS, OS version, architecture and file suffix specifiers are checked in this method.