00001 #include "bcwindowbase.inc" 00002 #include "condition.h" 00003 #include "mutex.h" 00004 #include "removethread.h" 00005 00006 #include <string.h> 00007 00008 extern "C" 00009 { 00010 #include <uuid/uuid.h> 00011 } 00012 00013 00014 00015 RemoveThread::RemoveThread() 00016 : Thread() 00017 { 00018 input_lock = new Condition(0, "RemoveThread::input_lock", 0); 00019 file_lock = new Mutex("RemoveThread::file_lock"); 00020 } 00021 00022 void RemoveThread::remove_file(char *path) 00023 { 00024 // Rename to temporary 00025 uuid_t id; 00026 uuid_generate(id); 00027 char string[BCTEXTLEN]; 00028 strcpy(string, path); 00029 uuid_unparse(id, string + strlen(string)); 00030 rename(path, string); 00031 printf("RemoveThread::run: renaming %s -> %s\n", path, string); 00032 00033 file_lock->lock("RemoveThread::remove_file"); 00034 files.append(strdup(string)); 00035 file_lock->unlock(); 00036 input_lock->unlock(); 00037 } 00038 00039 void RemoveThread::create_objects() 00040 { 00041 Thread::start(); 00042 } 00043 00044 void RemoveThread::run() 00045 { 00046 while(1) 00047 { 00048 char string[BCTEXTLEN]; 00049 string[0] = 0; 00050 input_lock->lock("RemoveThread::run"); 00051 file_lock->lock("RemoveThread::remove_file"); 00052 if(files.total) 00053 { 00054 strcpy(string, files.values[0]); 00055 files.remove_object_number(0); 00056 } 00057 file_lock->unlock(); 00058 if(string[0]) 00059 { 00060 printf("RemoveThread::run: deleting %s\n", string); 00061 remove(string); 00062 } 00063 } 00064 } 00065 00066
1.5.5