1 #include <lib/components/file_eraser.h>
2 #include <lib/base/ioprio.h>
3 #include <lib/base/eerror.h>
4 #include <lib/base/init.h>
5 #include <lib/base/init_num.h>
11 eBackgroundFileEraser *eBackgroundFileEraser::instance;
13 eBackgroundFileEraser::eBackgroundFileEraser()
14 :messages(this,1), stop_thread_timer(this)
18 CONNECT(messages.recv_msg, eBackgroundFileEraser::gotMessage);
19 CONNECT(stop_thread_timer.timeout, eBackgroundFileEraser::idle);
22 void eBackgroundFileEraser::idle()
27 eBackgroundFileEraser::~eBackgroundFileEraser()
29 messages.send(Message::quit);
34 void eBackgroundFileEraser::thread()
40 setIoPrio(IOPRIO_CLASS_BE, 7);
46 stop_thread_timer.stop();
49 void eBackgroundFileEraser::erase(const char *filename)
54 snprintf(buf, 255, "%s.$$$", filename);
55 if (rename(filename, buf)<0)
56 ;/*perror("rename file failed !!!");*/
59 messages.send(Message(Message::erase, strdup(buf)));
65 void eBackgroundFileEraser::gotMessage(const Message &msg )
72 if ( ::unlink(msg.filename) < 0 )
73 eDebug("remove file %s failed (%m)", msg.filename);
75 eDebug("file %s erased", msg.filename);
76 free((char*)msg.filename);
78 stop_thread_timer.start(1000, true); // stop thread in one seconds
84 eDebug("unhandled thread message");
88 eAutoInitP0<eBackgroundFileEraser> init_eBackgroundFilEraser(eAutoInitNumbers::configuration+1, "Background File Eraser");