1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/***************************************************************************
*
* $Header: /usr/local/cvsroot/utils/ytree/delete.c,v 1.12 2001/06/15 16:36:36 werner Exp $
*
* Loeschen von Dateien / Verzeichnissen
*
***************************************************************************/
#include "ytree.h"
extern int unlink(const char *);
extern int rmdir(const char *);
int DeleteFile(FileEntry *fe_ptr)
{
char filepath[PATH_LENGTH+1];
char buffer[PATH_LENGTH+1];
int result;
int term;
result = -1;
(void) GetFileNamePath( fe_ptr, filepath );
if( !S_ISLNK( fe_ptr->stat_struct.st_mode ) )
{
if( access( filepath, W_OK ) )
{
if( access( filepath, F_OK ) )
{
/* Datei existiert nicht ==> fertig */
goto UNLINK_DONE;
}
sprintf( buffer, "overriding mode %04o for \"%s\" (Y/N) ? ",
fe_ptr->stat_struct.st_mode & 0777, fe_ptr->name);
term = InputChoise( buffer, "YN\033" );
if( term != 'Y' )
{
(void) sprintf( message,
"Can't delete file*\"%s\"*%s",
filepath,
strerror(errno)
);
MESSAGE( message );
ESCAPE;
}
}
}
if( unlink( filepath ) )
{
(void) sprintf( message,
"Can't delete file*\"%s\"*%s",
filepath,
strerror(errno)
);
MESSAGE( message );
ESCAPE;
}
UNLINK_DONE:
/* File austragen */
/*----------------*/
result = RemoveFile( fe_ptr );
(void) GetAvailBytes( &statistic.disk_space );
FNC_XIT:
return( result );
}
int RemoveFile(FileEntry *fe_ptr)
{
DirEntry *de_ptr;
LONGLONG file_size;
de_ptr = fe_ptr->dir_entry;
file_size = fe_ptr->stat_struct.st_size;
de_ptr->total_bytes -= file_size;
de_ptr->total_files--;
statistic.disk_total_bytes -= file_size;
statistic.disk_total_files--;
if( fe_ptr->matching ) {
de_ptr->matching_bytes -= file_size;
de_ptr->matching_files--;
statistic.disk_matching_bytes -= file_size;
statistic.disk_matching_files--;
}
if( fe_ptr->tagged )
{
de_ptr->tagged_bytes -= file_size;
de_ptr->tagged_files--;
statistic.disk_tagged_bytes -= file_size;
statistic.disk_tagged_files--;
}
/* File austragen */
/*----------------*/
if( fe_ptr->next ) fe_ptr->next->prev = fe_ptr->prev;
if( fe_ptr->prev ) fe_ptr->prev->next = fe_ptr->next;
else
de_ptr->file = fe_ptr->next;
free( (char *) fe_ptr );
return( 0 );
}
|