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 &global_prefix, const FileTarget &tgt, const string &loc)
19 if(!tgt.is_installable() && loc.empty())
20 throw invalid_argument(tgt.get_name()+" is not installable");
24 if(!loc.compare(0, 2, "//"))
26 if(!tgt.get_package())
27 throw invalid_argument("No private install location for "+tgt.get_name());
29 prefix = tgt.get_package()->get_staging_directory();
34 prefix = global_prefix;
39 if(const Component *comp = tgt.get_component())
40 mid = comp->get_install_map().get_install_location(tgt);
43 mid = tgt.get_install_location();
45 return prefix/mid/FS::basename(tgt.get_path());
48 void InstalledFile::set_symlink(const FS::Path &l)
50 FS::Path al = FS::dirname(path)/l;
52 throw invalid_argument("InstalledFile::set_symlink");
53 link = FS::dirname(path)/l;
54 builder.get_vfs().register_path(link, this);
57 FileTarget *InstalledFile::get_real_target()
59 return source.get_real_target();
62 void InstalledFile::check_rebuild()
65 mark_rebuild("Does not exist");
66 else if(source.get_mtime()>mtime || source.get_size()!=size)
67 mark_rebuild(source.get_name()+" has changed");
68 else if(source.needs_rebuild())
69 mark_rebuild(source.get_name()+" needs rebuilding");
70 if(!needs_rebuild() && !link.empty())
73 mark_rebuild("Symlink does not exist");
76 FS::Path rel_path = FS::relative(path, FS::dirname(link));
77 if(FS::readlink(link)!=rel_path)
78 mark_rebuild("Symlink needs updating");
83 void InstalledFile::clean()
85 if(!link.empty() && mtime)