From: Mikko Rasa Date: Fri, 20 Jul 2012 19:43:12 +0000 (+0300) Subject: Improve cleaning X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1c43971ed99fd2f72ae171d6cdafabab74e37f4e;p=builder.git Improve cleaning --- diff --git a/source/builder.cpp b/source/builder.cpp index fde33cc..e6619b1 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -550,9 +550,11 @@ int Builder::do_clean() } for(set::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i) - if(FileTarget *ft = dynamic_cast(*i)) - if(ft->get_mtime()) - FS::unlink(ft->get_path()); + { + logger.log("tasks", format("RM %s", (*i)->get_name())); + if(!dry_run) + (*i)->clean(); + } return 0; } diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 58e1a7b..3d80147 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -131,3 +131,14 @@ void FileTarget::build_finished(bool success) Target::build_finished(success); } + +void FileTarget::clean() +{ + if(mtime) + { + FS::unlink(path); + mtime = Time::TimeStamp(); + size = 0; + check_rebuild(); + } +} diff --git a/source/filetarget.h b/source/filetarget.h index 6c12a5d..851085b 100644 --- a/source/filetarget.h +++ b/source/filetarget.h @@ -46,6 +46,9 @@ public: protected: virtual void build_finished(bool); + +public: + virtual void clean(); }; #endif diff --git a/source/installedfile.cpp b/source/installedfile.cpp index 6960cce..4638cc4 100644 --- a/source/installedfile.cpp +++ b/source/installedfile.cpp @@ -58,3 +58,10 @@ void InstalledFile::check_rebuild() else if(!link.empty() && !FS::exists(link)) mark_rebuild("Symlink does not exist"); } + +void InstalledFile::clean() +{ + if(!link.empty() && mtime) + FS::unlink(link); + FileTarget::clean(); +} diff --git a/source/installedfile.h b/source/installedfile.h index 0b9a455..1ce5f1e 100644 --- a/source/installedfile.h +++ b/source/installedfile.h @@ -25,6 +25,9 @@ public: virtual Target *get_real_target(); private: virtual void check_rebuild(); + +public: + virtual void clean(); }; #endif diff --git a/source/target.h b/source/target.h index f264905..5143dcf 100644 --- a/source/target.h +++ b/source/target.h @@ -122,6 +122,10 @@ public: protected: /** Handler for Task::signal_finished. */ virtual void build_finished(bool); + +public: + /** Removes any results of building the target. */ + virtual void clean() { } }; #endif