void create_parents (url u) { if (!exists (url_parent (u))) { if (!is_root (u)) create_parents (url_parent (u)); mkdir (url_parent (u)); } }
bool is_recursively_up_to_date (url dir) { if (!is_up_to_date (dir)) return false; bool error_flag; array<string> a= read_directory (dir, error_flag); for (int i=0; i<N(a); i++) if (url (a[i]) != url_here () && url (a[i]) != url_parent ()) if (is_directory (dir * a[i])) if (!is_recursively_up_to_date (dir * a[i])) return false; return true; }
url delta_sub (url base, url u) { if (is_atomic (base)) return u; if (is_concat (base) && is_concat (u) && (base[1] == u[1])) { if (is_special_root (base[1]) && is_concat (base[2]) && is_concat (u[2]) && base[2][1] != u[2][1]) return url_none (); return delta_sub (base[2], u[2]); } if (is_concat (base) && !is_semi_root (base)) return url_parent () * delta_sub (head (base), u); return url_none (); }
url operator * (url u1, url u2) { //cout << "concat " << u1->t << " * " << u2->t << "\n"; if (is_root (u2) || (is_concat (u2) && is_root (u2[1]))) { if (is_concat (u1) && is_root_web (u1[1])) { if (is_root (u2, "default") || (is_concat (u2) && is_root (u2[1], "default"))) { url v= u1[2]; while (is_concat (v)) v= v[1]; if (is_root (u2)) return u1[1] * v; return u1[1] * v * u2[2]; } if (is_root (u2, "blank") || (is_concat (u2) && is_root (u2[1], "blank"))) return reroot (u2, u1[1][1]->t->label); } return u2; } if (is_here (u1) || (u1->t == "")) return u2; if (is_here (u2)) return u1; if (is_none (u1)) return url_none (); if (is_none (u2)) return url_none (); if (u2 == url_parent ()) { if (is_root (u1)) return u1; if (is_pseudo_atomic (u1) && (!is_parent (u1))) return url_here (); if (is_semi_root (u1)) return u1; } if (is_concat (u2) && (u2[1] == url_parent ())) { if (is_root (u1)) return u1 * u2[2]; if (is_pseudo_atomic (u1) && (!is_parent (u1))) return u2[2]; if (is_semi_root (u1)) return u1 * u2[2]; } if (is_concat (u1)) return u1[1] * (u1[2] * u2); return as_url (tuple ("concat", u1->t, u2->t)); }
string concretize (url u) { // This routine transforms a resolved url into a system file name. // In the case of distant files from the web, a local copy is created. if (is_rooted (u, "default") || is_rooted (u, "file") || is_rooted (u, "blank")) return as_string (reroot (u, "default")); if (is_rooted_web (u)) return concretize (get_from_web (u)); if (is_rooted_tmfs (u)) return concretize (get_from_server (u)); if (is_ramdisc (u)) return concretize (get_from_ramdisc (u)); if (is_here (u)) return as_string (url_pwd ()); if (is_parent (u)) return as_string (url_pwd () * url_parent ()); if (is_wildcard (u, 1)) return u->t[1]->label; std_warning << "Couldn't concretize " << u->t << LF; // failed_error << "u= " << u << LF; // FAILED ("url has no root"); return "xxx"; }
tree evaluate_find_file (tree t) { int i, n=N(t); array<tree> r (n); for (i=0; i<n; i++) { r[i]= evaluate (t[i]); if (is_compound (r[i])) return evaluate_error ("bad find file"); } for (i=0; i<(n-1); i++) { url u= resolve (url (r[i]->label, r[n-1]->label)); if (!is_none (u)) { if (is_rooted (u, "default")) u= reroot (u, "file"); return as_string (u); } } url base_file_name (as_string (std_env["base-file-name"])); url u= resolve (base_file_name * url_parent () * r[n-1]->label); if (!is_none (u)) { if (is_rooted (u, "default")) u= reroot (u, "file"); return as_string (u); } return "false"; }
url delta_dir (url base, url sub) { return url_parent (delta (base * "dummy1", sub * "dummy2")); }
collection tmfs_get_projects (url u) { collection c= tmfs_query (seq ("root", "?prj", as_string (u)), "?prj"); if (N(c) != 0 || is_root (u)) return c; return tmfs_get_projects (url_parent (u)); }
inline url url_parent (url u) { return u * url_parent (); }
url head (url u) { return u * url_parent (); }