Changeset 3087 for trunk/tools


Ignore:
Timestamp:
Mar 11, 2000, 6:11:30 PM (26 years ago)
Author:
bird
Message:

Implemented optional directory locking to avoid conflicts during SMP makes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/bin/DoWithDirs.cmd

    r2919 r3087  
    1 /* $Id: DoWithDirs.cmd,v 1.3 2000-02-27 00:40:21 bird Exp $
     1/* $Id: DoWithDirs.cmd,v 1.4 2000-03-11 17:11:30 bird Exp $
    22 *
    3  * Syntax: dowithdirs.cmd [-e<list of excludes>] [-cp] [-i] <cmd with args...>
     3 * Syntax: dowithdirs.cmd [-e<list of excludes>] [-c] [-i] [-l] [-r] <cmd with args...>
    44 *    -e      Exclude directories.
    55 *    <list of excludes> is a INCLUDE-path styled list of directories.
    6  *    -cp     CD into the directory and execute the command.
     6 *    -c      CD into the directory and execute the command.
    77 *            Default action is to pass the directory name as last argument.
    88 *    -i      Ignore command failure (rc=0)
    99 *    -r      Process diretories in reverse order.
     10 *    -l      Lock directories for other dowithdirs.cmd processes. (-c required!)
    1011 */
    1112
     
    1718    asIgnore.0 = 0;
    1819    fCD = 0;
     20    fLocking = 0;
    1921    fReverse = 0;
    2022
    2123    /* parse arguments */
    22     parse arg sArg.1 sArg.2 sArg.3 sArg.4 sArg.5 sArg.6
    23     sArg.0 = 6;
     24    parse arg sArg.1 sArg.2 sArg.3 sArg.4 sArg.5 sArg.6 sArg.7
     25    sArg.0 = 7;
    2426    do i = 1 to sArg.0
    2527        if (sArg.i <> '') then
     
    6870                    end
    6971
     72                    when ch = 'L' then
     73                    do
     74                        fLocking = 1;
     75                    end
     76
    7077                    otherwise
    7178                        say 'unknown argument:' sArg.i;
     
    8895            call syntax;
    8996        end
     97    end
     98
     99    /* sanity check */
     100    if (fLocking & \fCD) then
     101    do
     102        say '-l (Locking) requires -cd to be specified!';
     103        call syntax;
    90104    end
    91105
     
    116130
    117131        if \fFound then
    118         do  /* execute the command */
     132        do
     133            /* switch execution type. */
    119134            if (fCD) then
    120135            do
     136                /* exectute the command in the directory */
    121137                say '# entering directory:' asDirs.i;
     138                /* save old dir and enter the new dir. */
    122139                sOldDir = directory();
    123140                call directory asDirs.i;
    124                 sCmds;
     141
     142                /* Lock the directory? */
     143                fOK = 1;
     144                if (fLocking) then
     145                    if (\lockdir()) then
     146                    do
     147                        say '# - warning: Skipping '|| asDirs.i || ' - directory was locked.';
     148                        fOK = 0;
     149                    end
     150
     151                /* continue only if locking was successful. */
     152                if (fOK) then
     153                do
     154                    /* execute command */
     155                    sCmds;
     156                    ret = rc;
     157
     158                    /* unlock directory */
     159                    if (fLocking & fOk) then
     160                        call unlockdir;
     161
     162                    /* check for return? */
     163                    if (ret <> 0) then
     164                    do
     165                        /* complain and fail if errors aren't ignored. */
     166                        say '# - rc = 'ret;
     167                        if (\fIgnoreFailure) then
     168                            exit(rc);
     169                    end
     170                end
     171
     172                /* restore old directory */
     173                call directory sOldDir;
    125174            end
    126175            else
     176            do
     177                /* execute the command with the directory as the last parameter */
    127178                sCmds filespec('name', asDirs.i);
    128 
    129             if (rc <> 0) then
    130             do
    131                 say 'rc='rc;
    132                 if (\fIgnoreFailure) then
    133                     exit(rc);
    134             end
    135 
    136             if (fCD) then
    137                 call directory sOldDir;
    138         end
     179                if (rc <> 0) then
     180                do
     181                    say '# - rc = ' || rc;
     182                    if (\fIgnoreFailure) then
     183                        exit(rc);
     184                end
     185            end
     186        end /* loop */
    139187    end
    140188
     
    143191
    144192syntax:
    145     say 'Syntax: dowithdirs.cmd [-e<list of excludes>] [-cp] [-i] <cmd with args...>';
     193    say 'Syntax: dowithdirs.cmd [-e<list of excludes>] [-c] [-i] [-l] [-r] <cmd with args...>';
    146194    say '   -e      Exclude directories.';
    147195    say '   <list of excludes> is a INCLUDE-path styled list of directories.';
    148     say '   -cp     CD into the directory and execute the command.';
     196    say '   -c      CD into the directory and execute the command.';
    149197    say '           Default action is to pass the directory name as last argument.';
    150198    say '   -i      Ignore command failure (rc=0)';
    151199    say '   -r      Process diretories in reverse order.';
     200    say '   -l      Lock directories for other dowithdirs.cmd processes. (-c required!)';
     201    exit(-1)
     202
     203
     204/*
     205 * Locks the directory by creating a .dirlocked file in the directory.
     206 * Returns  1 on success
     207 *          0 on error
     208 */
     209lockdir: procedure
     210    rc = stream('.dirlocked', 'c', 'open write');
     211    return substr(rc, 1, 5) = 'READY';
     212
     213
     214/*
     215 * Unlocks thedirectory by deleting the .dirlocked file.
     216 */
     217unlockdir: procedure
     218    rc = stream('.dirlocked', 'c', 'close');
     219    call SysFileDelete '.dirlocked';
     220    return 0;
     221
Note: See TracChangeset for help on using the changeset viewer.