1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
4 #include "installedfile.h"
5 #include "sharedlibrary.h"
10 InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const string &loc):
11 FileTarget(b, p, generate_target_path(b.get_prefix(), s, loc)),
14 add_dependency(source);
17 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc)
19 if(!tgt.is_installable() && loc.empty())
20 throw invalid_argument(tgt.get_name()+" is not installable");
25 else if(const Component *comp = tgt.get_component())
26 mid = comp->get_install_map().get_install_location(tgt);
28 mid = tgt.get_install_location();
30 string fn = tgt.get_install_filename();
32 fn = FS::basename(tgt.get_path());
37 void InstalledFile::set_symlink(const FS::Path &l)
39 link = FS::dirname(path)/l;
40 builder.get_vfs().register_path(link, this);
43 Target *InstalledFile::get_real_target()
45 return source.get_real_target();
48 void InstalledFile::check_rebuild()
51 mark_rebuild("Does not exist");
52 else if(source.get_mtime()>mtime || source.get_size()!=size)
53 mark_rebuild(source.get_name()+" has changed");
54 else if(source.needs_rebuild())
55 mark_rebuild(source.get_name()+" needs rebuilding");
56 if(!needs_rebuild() && !link.empty())
59 mark_rebuild("Symlink does not exist");
62 FS::Path rel_path = FS::relative(path, FS::dirname(link));
63 if(FS::readlink(link)!=rel_path)
64 mark_rebuild("Symlink needs updating");
69 void InstalledFile::clean()
71 if(!link.empty() && mtime)