]> git.tdb.fi Git - builder.git/commitdiff
Improve cleaning
authorMikko Rasa <tdb@tdb.fi>
Fri, 20 Jul 2012 19:43:12 +0000 (22:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 20 Jul 2012 20:56:07 +0000 (23:56 +0300)
source/builder.cpp
source/filetarget.cpp
source/filetarget.h
source/installedfile.cpp
source/installedfile.h
source/target.h

index fde33cc65bd821e1474afdb49986cb3b4250babf..e6619b1382ff91b02846117c264af9645b382472 100644 (file)
@@ -550,9 +550,11 @@ int Builder::do_clean()
        }
 
        for(set<Target *>::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i)
-               if(FileTarget *ft = dynamic_cast<FileTarget *>(*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;
 }
index 58e1a7b575fc8cc64306c3ecbaea27b4a688aaca..3d8014755de2b90dd2c81ff528f2e91029ca5278 100644 (file)
@@ -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();
+       }
+}
index 6c12a5df22e38fb54e7ff7433f6f26c6c4cc668c..851085ba040a1834c47a3967cfcec491a14efdf6 100644 (file)
@@ -46,6 +46,9 @@ public:
 
 protected:
        virtual void build_finished(bool);
+
+public:
+       virtual void clean();
 };
 
 #endif
index 6960ccead45599ca62cbc0f1302076fe80bd7682..4638cc40d6cec73cdb4b9af420c3d947da385523 100644 (file)
@@ -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();
+}
index 0b9a4557ab35313a064997739df1b557322948cd..1ce5f1e3851475f65b4eea3ab3fa212a5043f5bc 100644 (file)
@@ -25,6 +25,9 @@ public:
        virtual Target *get_real_target();
 private:
        virtual void check_rebuild();
+
+public:
+       virtual void clean();
 };
 
 #endif
index f264905ef829114eee8e638d608c0edac94037bb..5143dcf77fe0898895918b5588840259a5e39bc7 100644 (file)
@@ -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