#
# $Log: not supported by cvs2svn $
# Revision 1.6  2001/11/09 23:23:17  borland
# Excludes directories that are links.
#
# Revision 1.5  2001/11/09 21:18:12  borland
# Modified to prevent duplicate entries in the list of directories.
#
# Revision 1.4  2001/11/09 21:05:33  borland
# This version uses the 'diskList' parameter of the config file.  It searches
# for the named directories on each disk.
#
# Revision 1.3  2001/10/24 16:44:51  borland
# Added log message header.
#
#

proc APSExpandSDDSSpaceUsedDirList {args} {
    APSDefineMonitoringVariables
    global apsDataManagerNormalEmail

    set configFile ""
    if {[APSStrictParseArguments {configFile}] || ![string length $configFile]} {
        return -code error "APSExpandSDDSSpaceUsedDirList: bad config file: $configFile"
    }
    if ![file exists $configFile] {
        return -code error "APSExpandSDDSSpaceUsedDirList: not found: $configFile"
    }
    
    if [catch {sdds load $configFile config} result] {
        return -code error "APSExpandSDDSSpaceUsedDirList: unable to load $configFile: $result"
    }
    set diskList [split [lindex $config(Parameter.diskList) 0] ]
    
    set errorList ""
    set dirList ""
    foreach dir0 [lindex $config(Column.Directory) 0] isParent [lindex $config(Column.IsParent) 0] {
        set found 0
        foreach disk $diskList {
            set dir /home/$disk/$dir0 
            if ![file exists $dir] {
                continue
            }
            if [string compare [file type $dir] link]==0 continue
            if ![file isdir $dir] {
                lappend errorList "not a directory: $dir"
                continue
            }
            incr found 1
            if [catch {cd $dir} result] {
                lappend errorList "unable to change to directory $dir: $result"
                continue
            }
            if {$dir != [pwd]} {
                #We are inside a symlink somewhere in a higher level directory
                continue
            }
            if !$isParent {
                if [lsearch -exact $dirList $dir]==-1 {
                    lappend dirList $dir
                }
            } else {
                foreach file [glob -nocomplain *] {
                    if {[file isdir $file] && \
                          [string compare [file type $file] link]!=0 && \
                          [lsearch -exact $dirList $dir/$file]==-1} {
                        lappend dirList $dir/$file
                    }
                }
            }
        }
        if !$found {
            lappend errorList "not found: $dir0"
        }
    }
    if [llength $errorList] {
        APSSendEMail -address $apsDataManagerNormalEmail -message "$errorList" \
          -subject "Errors from sddsSpaceUsed"
    }
    return $dirList
}

