Subversion Repositories DevTools

Rev

Rev 2313 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2313 Rev 2354
Line 22... Line 22...
22
**                          (c) CopyFile
22
**                          (c) CopyFile
23
**                          (d) DeleteFile
23
**                          (d) DeleteFile
24
**                          (r) Remove Files (wildcard)
24
**                          (r) Remove Files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
26
**                          (T) Delete Directory Trees
26
**                          (T) Delete Directory Trees
27
**                          (R) Delete Empty Directories
27
**                          (R) Remove Files and Empty Directories
28
**
28
**
29
**                      Example Usage
29
**                      Example Usage
30
**
30
**
31
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
31
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
32
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
32
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
33
**                          JatsFileUtil r9 'deleteFile'  a1 b2 c3
33
**                          JatsFileUtil r9 'deleteFile'  a1 b2 c3
34
**                          JatsFileUtil D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
34
**                          JatsFileUtil D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
35
**                          JatsFileUtil T9 'DeleteTree'  interface
35
**                          JatsFileUtil T9 'DeleteTree'  interface
36
**                          JatsFileUtil R9 'RmDir'       build
36
**                          JatsFileUtil R9 'RmItem'       build
37
**
37
**
38
**                      First two arguments are common to all
38
**                      First two arguments are common to all
39
**                          argv[1]     - Mode specifier, Debug specifier
39
**                          argv[1]     - Mode specifier, Debug specifier
40
**                          argv[2]     - Display Text
40
**                          argv[2]     - Display Text
41
**
41
**
Line 55... Line 55...
55
#include <string.h>
55
#include <string.h>
56
 
56
 
57
void ErrorExit (char * lpszMessage, char * lpszMessage2);
57
void ErrorExit (char * lpszMessage, char * lpszMessage2);
58
void createPaths ( char *path );
58
void createPaths ( char *path );
59
void DeleteDir( int argc, char* argv[] );
59
void DeleteDir( int argc, char* argv[] );
60
void DeleteDirTree( int argc, char* argv[] );
-
 
61
char * makePath( char *base, char *path);
60
char * makePath( char *base, char *path);
62
int DeleteOneFile (char * dst );
-
 
63
void DeleteOneDirectoryTree( char* baseDir );
61
void DeleteOneDirectoryTree( char* baseDir );
64
void copyOneFile( int argc, char* argv[] );
62
void copyOneFile( int argc, char* argv[] );
65
int CopyFile ( char *src, char *dst, mode_t st_mode );
63
int CopyFile ( char *src, char *dst, mode_t st_mode );
66
void RmDir( int argc, char* argv[] );
64
void RmItem( int argc, char* argv[] );
67
int wildcmp(char *string, char *wild );
65
int wildcmp(char *string, char *wild );
-
 
66
int DeleteOneFile (char * dst );
-
 
67
void DeleteOneDirectory (char *path );
-
 
68
void stdCheck( char *name, int argBad, char *txt );
68
 
69
 
69
/*
70
/*
70
**  Global
71
**  Global
71
*/
72
*/
72
char  verbose = 1;                          /* Debugging aid */
73
char  verbose = 1;                          /* Debugging aid */
-
 
74
char  *helpText =
-
 
75
         "Usage: JatsFileUtil Mode Text Arguments\n"
-
 
76
         "\n"
-
 
77
         "  Where 'Mode' is two characters:\n"
-
 
78
         "      1 - Operation Specifier\n"
-
 
79
         "      2 - Debug Mode. 0..9\n"
-
 
80
         "  Where 'Text' is a, possibly empty, display string\n"
-
 
81
         "\n"
-
 
82
         "  By Example:\n"
-
 
83
         "      c9 copyFile     dstPath srcPath chmod\n"
-
 
84
         "      d9 unCopyFile   dstPath\n"
-
 
85
         "      r9 RmFile       file+\n"
-
 
86
         "      D9 DeleteFiles  dstDir file+ - supports (?*)\n"
-
 
87
         "      T9 DeleteTree   dstDir+\n"
-
 
88
         "      R9 RmItem       (dir|file)+\n";
73
 
89
 
74
/*----------------------------------------------------------------------------
90
/*----------------------------------------------------------------------------
75
** FUNCTION           : main
91
** FUNCTION           : main
76
**
92
**
77
** DESCRIPTION        : Main entry points
93
** DESCRIPTION        : Main entry points
Line 84... Line 100...
84
**
100
**
85
----------------------------------------------------------------------------*/
101
----------------------------------------------------------------------------*/
86
 
102
 
87
int main(int argc, char* argv[])
103
int main(int argc, char* argv[])
88
{
104
{
-
 
105
    int ii;
-
 
106
    
89
    /*
107
    /*
90
    **  User must provide some thing
108
    **  User must provide some thing
91
    */
109
    */
92
    if ( argc < 2 )
110
    if ( argc < 2 )
93
    {
111
    {
94
        ErrorExit("Insufficient arguments","");
112
       fprintf(stderr, helpText );
-
 
113
       return 1;
95
    }
114
    }
96
 
115
 
97
    /*
116
    /*
98
    **  Examine the first argument
117
    **  Examine the first argument
99
    **  Must be a character string of
118
    **  Must be a character string of
Line 107... Line 126...
107
        /*
126
        /*
108
        **  If Verbose, then display arguments
127
        **  If Verbose, then display arguments
109
        */
128
        */
110
        if ( verbose > 2 )
129
        if ( verbose > 2 )
111
        {
130
        {
112
            int ii;
-
 
113
            for ( ii = 0; ii < argc ; ii++ )
131
            for ( ii = 0; ii < argc ; ii++ )
114
            {
132
            {
115
                fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
133
                fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
116
            }
134
            }
117
            fflush(stderr) ;
135
            fflush(stderr) ;
Line 129... Line 147...
129
        **      argv[3] - target path
147
        **      argv[3] - target path
130
        **      argv[4] - Source path
148
        **      argv[4] - Source path
131
        **      argv[5] - File attributes
149
        **      argv[5] - File attributes
132
        */
150
        */
133
        case 'c':
151
        case 'c':
-
 
152
            stdCheck( "CopyFile", argc != 6, NULL );
-
 
153
            fprintf(stderr, "---- %s %s\n", argv[2], argv[3]);
-
 
154
            fflush(stderr) ;
134
            copyOneFile(argc, argv);
155
            copyOneFile(argc, argv);
135
            break;
156
            break;
136
 
157
 
137
        /*
158
        /*
138
        **  UnCopy a file
159
        **  UnCopy a file
139
        **      argv[2] - Text
160
        **      argv[2] - Text
140
        **      argv[3] - target path
161
        **      argv[3] - target path
141
        */
162
        */
142
        case 'd':
163
        case 'd':
143
            {
-
 
144
                if ( argc != 4 )
164
            stdCheck( "UnCopy", argc != 4, NULL );
145
                    ErrorExit("Incorrect argument count for mode","");
165
            fprintf(stderr, "---- %s %s\n", argv[2], argv[3]);
-
 
166
            fflush(stderr) ;
146
 
167
 
147
                /*
-
 
148
                **  Display user text
-
 
149
                */
-
 
150
                fprintf(stderr, "---- %s %s\n", argv[2], argv[3]);
-
 
151
                fflush(stderr) ;
-
 
152
                DeleteOneFile(argv[3]);
168
            DeleteOneFile(argv[3]);
153
            }
-
 
154
            break;
169
            break;
155
 
170
 
156
        /*
171
        /*
157
        **  Remove named files
172
        **  Remove named files
158
        **      argv[2]     - Text
173
        **      argv[2]     - Text
159
        **      argv[3]+    - target path
174
        **      argv[3]+    - target path
160
        */
175
        */
161
        case 'r':
176
        case 'r':
162
                {
-
 
163
                    int ii;
-
 
164
 
-
 
165
                    if ( argc < 4 )
-
 
166
                        ErrorExit("Incorrect argument count for mode","");
-
 
167
 
-
 
168
                    /*
-
 
169
                    **  Display user text
-
 
170
                    */
-
 
171
                    if ( argv[2][0] )
-
 
172
                    {
-
 
173
                        fprintf(stderr, "%s\n", argv[2]);
177
            stdCheck( "RmFile", argc <= 3, argv[2] );
174
                        fflush(stderr) ;
-
 
175
                    }
-
 
176
 
-
 
177
                    for ( ii = 3; ii < argc ; ii++ )
178
            for ( ii = 3; ii < argc ; ii++ )
178
                    {
179
            {
179
                        DeleteOneFile(argv[ii]);
180
                DeleteOneFile(argv[ii]);
180
                    }
-
 
181
                }
181
            }
182
            break;
182
            break;
183
 
183
 
184
        /*
184
        /*
185
        **  Delete files in directory - with wildcards
185
        **  Delete files in directory - with wildcards
186
        **      argv[2]     - Text
186
        **      argv[2]     - Text
187
        **      argv[3]     - Base directory
187
        **      argv[3]     - Base directory
188
        **      argv[4]+    - Files in dir to delete.
188
        **      argv[4]+    - Files in dir to delete.
189
        */
189
        */
190
        case 'D':
190
        case 'D':
-
 
191
            stdCheck( "DeleteDir", argc < 4, argv[2] );
191
            DeleteDir(argc - 2, argv + 2 );
192
            DeleteDir(argc, argv );
192
            break;
193
            break;
193
 
194
 
194
        /*
195
        /*
195
        **  Delete files recursively
196
        **  Delete files recursively
196
        **      argv[2] - Text
197
        **      argv[2] - Text
197
        **      argv[3]+  Base directory
198
        **      argv[3]+  Base directory
198
        */
199
        */
199
        case 'T':
200
        case 'T':
200
            DeleteDirTree(argc - 2, argv + 2 );
201
            stdCheck( "DeleteDirTree", argc < 3, argv[2] );
-
 
202
            for ( ii = 3; ii < argc ; ii++)
-
 
203
            {
-
 
204
                DeleteOneDirectoryTree( argv[ii] );
-
 
205
            }
201
            break;
206
            break;
202
 
207
 
203
        /*
208
        /*
204
        **  Delete Empty Directories
209
        **  Delete Empty Directories
205
        **      argv[2] - Text
210
        **      argv[2] - Text
206
        **      argv[3]+  Base directory
211
        **      argv[3]+  Base directory
207
        */
212
        */
208
        case 'R':
213
        case 'R':
-
 
214
            stdCheck( "RmItem", argc < 3, argv[2] );
209
            RmDir(argc - 2, argv + 2 );
215
            RmItem(argc, argv );
210
            break;
216
            break;
211
            
217
            
212
            
218
            
213
        default :
219
        default :
214
            ErrorExit("Unknown mode: ",argv[1]);
220
            ErrorExit("Unknown mode: ",argv[1]);
Line 216... Line 222...
216
    }
222
    }
217
    return 0;
223
    return 0;
218
}
224
}
219
 
225
 
220
/*----------------------------------------------------------------------------
226
/*----------------------------------------------------------------------------
-
 
227
** FUNCTION           : stdCheck
-
 
228
**
-
 
229
** DESCRIPTION        : Check arg count
-
 
230
**                      Print standard header
-
 
231
**
-
 
232
**
-
 
233
** INPUTS             : name        - Name of the operation
-
 
234
**                      argBad      - Arg count Not Ok
-
 
235
**                      text        - Text to print
-
 
236
**
-
 
237
** RETURNS            : Will not return on error
-
 
238
**
-
 
239
----------------------------------------------------------------------------*/
-
 
240
 
-
 
241
void stdCheck( char *name, int argBad, char *txt )
-
 
242
{
-
 
243
    if ( argBad  )
-
 
244
    {
-
 
245
       fprintf(stderr, "JatsFileUtil:Incorrect argument count for %s\n", name);
-
 
246
       ErrorExit(NULL, NULL);
-
 
247
    }
-
 
248
 
-
 
249
    /*
-
 
250
    **  Display user text
-
 
251
    **      Suppress display if the message is empty
-
 
252
    */
-
 
253
    if ( txt && *txt )
-
 
254
    {
-
 
255
        fprintf(stderr, "%s\n",txt);
-
 
256
        fflush(stderr) ;
-
 
257
    }
-
 
258
}
-
 
259
 
-
 
260
 
-
 
261
/*----------------------------------------------------------------------------
221
** FUNCTION           : createPaths
262
** FUNCTION           : createPaths
222
**
263
**
223
** DESCRIPTION        : Create the path to the target
264
** DESCRIPTION        : Create the path to the target
224
**
265
**
225
**
266
**
Line 284... Line 325...
284
	int    rv;
325
	int    rv;
285
    char * src;
326
    char * src;
286
    char * dst;
327
    char * dst;
287
    struct stat fstat;
328
    struct stat fstat;
288
    
329
    
289
    if ( argc != 6 )
-
 
290
        ErrorExit("Incorrect argument count for file copy","");
-
 
291
    
-
 
292
    /*
-
 
293
    **  Display user text
-
 
294
    */
-
 
295
    fprintf(stderr, "---- %s %s\n", argv[2], argv[3]);
-
 
296
    fflush(stderr) ;
-
 
297
 
-
 
298
    dst = argv[3];
330
    dst = argv[3];
299
    src = argv[4];
331
    src = argv[4];
300
 
332
 
301
    /*
333
    /*
302
    **   Check that the source is a file
334
    **   Check that the source is a file
303
    */
335
    */
304
    if ( verbose )
336
    if ( verbose > 2)
305
        fprintf(stderr, "Validate Source File: %s\n", src);
337
        fprintf(stderr, "Validate Source File: %s\n", src);
306
        
338
        
307
    rv = stat( src, &fstat );
339
    rv = stat( src, &fstat );
308
    if ( rv != 0 )
340
    if ( rv != 0 )
309
    {
341
    {
Line 311... Line 343...
311
        fprintf(stderr, "Source: %s\n", src);
343
        fprintf(stderr, "Source: %s\n", src);
312
        ErrorExit("Source File not found: ", argv[4]);
344
        ErrorExit("Source File not found: ", argv[4]);
313
    }
345
    }
314
 
346
 
315
    /*
347
    /*
316
    **  Remove the ReadOnly attribute on the dest file
348
    **  Delete the destination file before the copy
-
 
349
    **  Will force it to be writable
317
    */
350
    */
318
    DeleteOneFile(dst);
351
    DeleteOneFile(dst);
319
 
352
 
320
    /*
353
    /*
321
    **  Create directories
354
    **  Create directories
Line 333... Line 366...
333
    }
366
    }
334
 
367
 
335
    /*
368
    /*
336
    **  Test for files existence
369
    **  Test for files existence
337
    */
370
    */
338
    if ( verbose )
371
    if ( verbose > 1 )
339
        fprintf(stderr, "Test target was copied: %s\n", dst);
372
        fprintf(stderr, "Test target was copied: %s\n", dst);
340
 
373
 
341
    rv = stat( dst, &fstat );
374
    rv = stat( dst, &fstat );
342
    if ( rv != 0 )
375
    if ( rv != 0 )
343
    {
376
    {
Line 375... Line 408...
375
        if ( verbose > 1)
408
        if ( verbose > 1)
376
            fprintf(stderr, "Set target executable: %s\n", dst);
409
            fprintf(stderr, "Set target executable: %s\n", dst);
377
        fstat.st_mode &= ~( S_IXUSR | S_IXOTH | S_IXGRP );
410
        fstat.st_mode &= ~( S_IXUSR | S_IXOTH | S_IXGRP );
378
    }
411
    }
379
        
412
        
380
    if ( verbose )
413
    if ( verbose > 1 )
381
        fprintf(stderr, "Set target perms: %s, 0%o\n", dst, fstat.st_mode);
414
        fprintf(stderr, "Set target perms: %s, 0%o\n", dst, fstat.st_mode);
382
    rv = chmod( dst, fstat.st_mode );
415
    rv = chmod( dst, fstat.st_mode );
383
    if ( rv != 0 )
416
    if ( rv != 0 )
384
    {
417
    {
385
        ErrorExit("Setting ReadOnly: ", argv[3]);
418
        ErrorExit("Setting ReadOnly: ", argv[3]);
Line 409... Line 442...
409
     int in;
442
     int in;
410
     int out;
443
     int out;
411
     int ferror = 0;
444
     int ferror = 0;
412
    char buffer[COPYSIZE] = { '\0' } ;
445
    char buffer[COPYSIZE] = { '\0' } ;
413
 
446
 
414
    if ( verbose )
447
    if ( verbose > 2 )
415
    {
448
    {
416
        fprintf(stderr, "CopyFile: Output Mode: 0%o\n", st_mode);
449
        fprintf(stderr, "CopyFile: Output Mode: 0%o\n", st_mode);
417
        fflush(stderr) ;
450
        fflush(stderr) ;
418
    }
451
    }
419
 
452
 
Line 460... Line 493...
460
**                      Then delete the directory - if its empty
493
**                      Then delete the directory - if its empty
461
**
494
**
462
**
495
**
463
** INPUTS             : argc    - count of args
496
** INPUTS             : argc    - count of args
464
**                      argv    - list of files to delete
497
**                      argv    - list of files to delete
465
**                                [0]:  Text to display
-
 
466
**                                [1]:  Base directory
498
**                                [3]:  Base directory
467
**                                [2]+  Files in dir to delete
499
**                                [4]+  Files in dir to delete
468
**
500
**
469
** RETURNS            : Will not return on error
501
** RETURNS            : Will not return on error
470
**
502
**
471
----------------------------------------------------------------------------*/
503
----------------------------------------------------------------------------*/
472
 
504
 
Line 477... Line 509...
477
    char* baseDir;
509
    char* baseDir;
478
    DIR *dir;
510
    DIR *dir;
479
    struct dirent *dirent;
511
    struct dirent *dirent;
480
    char *target;
512
    char *target;
481
 
513
 
482
    if ( argc < 3 )
-
 
483
        ErrorExit("Insufficient arguments for DeleteDir","");
-
 
484
 
-
 
485
    /*
-
 
486
    **  Display the user message
-
 
487
    **      Supress display if the message is empty
-
 
488
    */
-
 
489
    if ( argv[0][0] )
-
 
490
    {
-
 
491
        fprintf(stderr, "%s\n", argv[0]);
-
 
492
        fflush(stderr) ;
-
 
493
    }
-
 
494
 
514
 
495
    /*
515
    /*
496
    **  Extract the base directory from the argument list
516
    **  Extract the base directory from the argument list
497
    **  This must be a directory
517
    **  This must be a directory
498
    */
518
    */
499
    baseDir = argv[1];
519
    baseDir = argv[3];
500
    argc -= 2;
-
 
501
    argv+=2;
-
 
502
 
520
 
503
    /*
521
    /*
504
    **  Ensure that the base directory exists
522
    **  Ensure that the base directory exists
505
    */
523
    */
506
    rv = stat( baseDir, &fstat );
524
    rv = stat( baseDir, &fstat );
507
    if ( rv != 0 )
525
    if ( rv != 0 )
508
    {
526
    {
509
        /*
527
        /*
510
        **  Directory does not exists
528
        **  Directory does not exists
511
        **  Assume its aleady deleted
529
        **  Assume its already deleted
512
        */
530
        */
513
        if ( verbose > 1 )
531
        if ( verbose > 1 )
514
            fprintf(stderr, "Base dir does not exist: %s\n", baseDir);
532
            fprintf(stderr, "Base dir does not exist: %s\n", baseDir);
515
        return;
533
        return;
516
    }
534
    }
Line 558... Line 576...
558
            fprintf(stderr, "Directory Entry:%s,%s\n", baseDir, dirent->d_name );
576
            fprintf(stderr, "Directory Entry:%s,%s\n", baseDir, dirent->d_name );
559
        
577
        
560
        /*
578
        /*
561
        **  Compare against each item in the user list
579
        **  Compare against each item in the user list
562
        */
580
        */
563
        for ( ii = 0; ii < argc ; ii++)
581
        for ( ii = 4; ii < argc ; ii++)
564
        {
582
        {
565
 
583
 
566
            if ( wildcmp(dirent->d_name, argv[ii] )  )
584
            if ( wildcmp(dirent->d_name, argv[ii] )  )
567
            {
585
            {
568
                if ( verbose > 1 )
586
                if ( verbose > 1 )
Line 583... Line 601...
583
    **  Finally delete the diretory
601
    **  Finally delete the diretory
584
    **      Unless its '.'
602
    **      Unless its '.'
585
    */
603
    */
586
    if ( strcmp( ".", baseDir) != 0 )
604
    if ( strcmp( ".", baseDir) != 0 )
587
    {
605
    {
588
        if ( verbose > 1 )
-
 
589
            fprintf(stderr, "Delete Directory: %s\n", baseDir);
-
 
590
        
-
 
591
        if ( rmdir (baseDir ) )
-
 
592
        {
-
 
593
            if ( verbose )
-
 
594
                fprintf(stderr, "Directory not deleted: %s\n", baseDir);
-
 
595
        }
-
 
596
    }
-
 
597
}
-
 
598
 
-
 
599
/*----------------------------------------------------------------------------
-
 
600
** FUNCTION           : DeleteDirTree
-
 
601
**
-
 
602
** DESCRIPTION        : Delete an entire directory tree(s)
-
 
603
**
-
 
604
** INPUTS             : argc    - count of args
-
 
605
**                      argv    - list of files to delete
-
 
606
**                                [0]:  Text to display
-
 
607
**                                [1]+  Base directory
-
 
608
**
-
 
609
** RETURNS            : Will not return on error
-
 
610
**
-
 
611
----------------------------------------------------------------------------*/
-
 
612
 
-
 
613
void DeleteDirTree( int argc, char* argv[] )
-
 
614
{
-
 
615
    int ii;
-
 
616
 
-
 
617
    if ( argc < 2 )
-
 
618
        ErrorExit("Insufficient arguments for DeleteDirTree","");
-
 
619
        
-
 
620
    /*
-
 
621
    **  Display the user message
-
 
622
    **      Supress display if the message is empty
-
 
623
    */
-
 
624
    if ( argv[0][0] )
-
 
625
    {
-
 
626
        fprintf(stderr, "%s\n", argv[0]);
-
 
627
        fflush(stderr) ;
-
 
628
    }
-
 
629
 
-
 
630
    for ( ii = 1; ii < argc ; ii++)
-
 
631
    {
-
 
632
        DeleteOneDirectoryTree( argv[ii] );
606
        DeleteOneDirectory(baseDir);
633
    }
607
    }
634
}
608
}
635
 
609
 
636
/*----------------------------------------------------------------------------
610
/*----------------------------------------------------------------------------
637
** FUNCTION           : DeleteOneDirectoryTree
611
** FUNCTION           : DeleteOneDirectoryTree
Line 734... Line 708...
734
    }
708
    }
735
    closedir(dir);
709
    closedir(dir);
736
 
710
 
737
    /*
711
    /*
738
    **  Finally delete the directory
712
    **  Finally delete the directory
-
 
713
    **  It should now be empty
739
    */
714
    */
740
    if ( verbose )
-
 
741
        fprintf(stderr, "Delete Directory: %s\n", baseDir);
715
    DeleteOneDirectory(baseDir);
-
 
716
}
742
 
717
 
-
 
718
/*----------------------------------------------------------------------------
-
 
719
** FUNCTION           : RmItem
-
 
720
**
-
 
721
** DESCRIPTION        : Remove Empty directories and files
-
 
722
**
-
 
723
** INPUTS             : argc    - count of args
-
 
724
**                      argv    - list of files to delete
-
 
725
**                                [3]+  Base directory
-
 
726
**
-
 
727
** RETURNS            : Will not return on error
-
 
728
**
-
 
729
----------------------------------------------------------------------------*/
-
 
730
 
-
 
731
void RmItem( int argc, char* argv[] )
-
 
732
{
-
 
733
    int ii;
-
 
734
    struct stat fstat;
-
 
735
 
-
 
736
 
743
    if ( rmdir (baseDir ) )
737
    for ( ii = 3; ii < argc ; ii++)
744
    {
738
    {
-
 
739
        int rv;
-
 
740
 
745
        if ( verbose )
741
        if ( verbose > 2)
746
            fprintf(stderr, "Directory not deleted: %s\n", baseDir);
742
            fprintf(stderr, "RmItem: %s\n", argv[ii]);
-
 
743
 
-
 
744
        rv = lstat( argv[ii], &fstat );
-
 
745
        if ( rv == 0 )
-
 
746
        {
-
 
747
            if (fstat.st_mode & S_IFDIR)
-
 
748
            {
-
 
749
                DeleteOneDirectory(argv[ii]);
-
 
750
            }
-
 
751
            else
-
 
752
            {
-
 
753
                DeleteOneFile(argv[ii]);
-
 
754
            }
-
 
755
        }
747
    }
756
    }
748
}
757
}
749
 
758
 
750
/*----------------------------------------------------------------------------
759
/*----------------------------------------------------------------------------
751
** FUNCTION           : DeleteOneFile
760
** FUNCTION           : DeleteOneFile
752
**
761
**
753
** DESCRIPTION        : Delete a file
762
** DESCRIPTION        : Delete a file
-
 
763
**                      Low level deletion operation to be used by other functions
754
**                      Force it writable before deletion
764
**                      Force it writable before deletion
755
**                      Don't follow symbolic links - just delete them
765
**                      Don't follow symbolic links - just delete them
756
**
766
**
757
** INPUTS             : path        - path to the file
767
** INPUTS             : path        - path to the file
758
**
768
**
Line 788... Line 798...
788
        {
798
        {
789
            fprintf(stderr, "Warning: Did not remove file: %s\n", dst);
799
            fprintf(stderr, "Warning: Did not remove file: %s\n", dst);
790
            result = 1;
800
            result = 1;
791
        }
801
        }
792
    }
802
    }
-
 
803
 
793
    return result;
804
    return result;
794
}
805
}
795
 
806
 
796
/*----------------------------------------------------------------------------
807
/*----------------------------------------------------------------------------
797
** FUNCTION           : RmDir
808
** FUNCTION           : DeleteOneDirectory
798
**
809
**
799
** DESCRIPTION        : Remove Empty directories
810
** DESCRIPTION        : Low level function to delete a directory
-
 
811
**                      Assumes that checks have been performed
-
 
812
**                          It is a directory
-
 
813
**                          It does exist
800
**
814
**
801
** INPUTS             : argc    - count of args
-
 
802
**                      argv    - list of files to delete
-
 
803
**                                [0]:  Text to display
-
 
804
**                                [1]+  Base directory
-
 
805
**
815
**
-
 
816
** INPUTS             : path            - Target Path
-
 
817
**
806
** RETURNS            : Will not return on error
818
** RETURNS            : Nothing
807
**
819
**
808
----------------------------------------------------------------------------*/
820
----------------------------------------------------------------------------*/
809
 
821
 
810
void RmDir( int argc, char* argv[] )
822
void DeleteOneDirectory (char *path )
811
{
823
{
812
    int ii;
-
 
813
 
-
 
814
    if ( argc < 2 )
824
    if ( verbose )
815
        ErrorExit("Insufficient arguments for RmDir","");
-
 
816
        
-
 
817
    /*
-
 
818
    **  Display the user message
-
 
819
    **      Suppress display if the message is empty
-
 
820
    */
-
 
821
    if ( argv[0][0] )
-
 
822
    {
-
 
823
        fprintf(stderr, "%s\n", argv[0]);
825
        fprintf(stderr, "Delete Directory: %s\n", path);
824
        fflush(stderr) ;
-
 
825
    }
-
 
826
 
826
 
827
    for ( ii = 1; ii < argc ; ii++)
827
    if ( rmdir(path))
828
    {
828
    {
829
        if ( verbose > 2)
829
        if ( verbose )
830
            fprintf(stderr, "RmDir: %s\n", argv[ii]);
-
 
831
        
-
 
832
        if ( rmdir (argv[ii] ) )
-
 
833
        {
-
 
834
            if ( verbose )
-
 
835
                fprintf(stderr, "Directory not deleted: %s\n", argv[ii]);
830
            fprintf(stderr, "Directory not deleted: %s\n", path);
836
        }
-
 
837
    }
831
    }
838
}
832
}
839
 
833
 
840
/*----------------------------------------------------------------------------
834
/*----------------------------------------------------------------------------
841
** FUNCTION           : makePath
835
** FUNCTION           : makePath
842
**
836
**
843
** DESCRIPTION        : Create a path from two elements
837
** DESCRIPTION        : Create a path from two elements
-
 
838
**                      Join 2 components together
844
**                      Allocate memory
839
**                      Allocate memory
845
**
840
**
846
**
841
**
847
** INPUTS             : base        - Part 1
842
** INPUTS             : base        - Part 1
848
**                      file        - Part 2
843
**                      file        - Part 2 or NULL
849
**
844
**
850
** RETURNS            :
845
** RETURNS            :
851
**
846
**
852
----------------------------------------------------------------------------*/
847
----------------------------------------------------------------------------*/
853
 
848
 
Line 944... Line 939...
944
**
939
**
945
----------------------------------------------------------------------------*/
940
----------------------------------------------------------------------------*/
946
 
941
 
947
void ErrorExit (char * lpszMessage, char * lpszMessage2)
942
void ErrorExit (char * lpszMessage, char * lpszMessage2)
948
{ 
943
{ 
-
 
944
    if ( lpszMessage  )
-
 
945
    {
949
   fprintf(stderr, "JatsFileUtil:Error: %s%s\n", lpszMessage,lpszMessage2);
946
        fprintf(stderr, "JatsFileUtil:Error:%s%s\n", lpszMessage,lpszMessage2);
-
 
947
    }
950
   fflush(stderr) ;
948
   fflush(stderr) ;
951
   exit(-1);
949
   exit(-1);
952
} 
950
} 
953
 
951