static void d_link(struct dirent *f_drt, t_list **lst, char *arg, t_opt opt) { t_list *lst_tmp; if (opt.a) { if (!(lst_tmp = mk_link(arg, f_drt->d_name))) return ; ft_lstadd(lst, lst_tmp); } else if (opt.aa) { if (ft_strcmp(f_drt->d_name, ".") && ft_strcmp(f_drt->d_name, "..")) { if (!(lst_tmp = mk_link(arg, f_drt->d_name))) return ; ft_lstadd(lst, lst_tmp); } } else if (*(f_drt->d_name) != '.') { if (!(lst_tmp = mk_link(arg, f_drt->d_name))) return ; ft_lstadd(lst, lst_tmp); } }
int lnk_creat(ARCHD *arcn, int *payload) { struct stat sb; /* * Check if this hardlink carries the "payload". In "cpio" archives * it's usually the last record of a set of hardlinks which includes * the contents of the file. * */ *payload = S_ISREG(arcn->sb.st_mode) && (arcn->sb.st_size > 0) && (arcn->sb.st_size <= arcn->skip); /* * We may be running as root, so we have to be sure that link target * is not a directory, so we lstat and check. XXX: This is still racy. */ if (lstat(arcn->ln_name, &sb) != -1 && S_ISDIR(sb.st_mode)) { tty_warn(1, "A hard link to the directory %s is not allowed", arcn->ln_name); return -1; } return mk_link(arcn->ln_name, &sb, arcn->name, 0); }
/* extract_references -- go through node tree and find elements we need to reference; e.g. links, images, citations, footnotes Copy them from main parse tree */ void extract_references(node *list, scratch_pad *scratch) { node *temp; char * temp_str; link_data *l; while (list != NULL) { switch (list->key) { case LINKREFERENCE: l = list->link_data; temp_str = lower_string(l->label); temp = mk_link(list->children, temp_str, l->source, l->title, NULL); temp->link_data->attr = copy_node_tree(l->attr); /* store copy of link reference */ scratch->links = cons(temp, scratch->links); free(temp_str); break; case NOTESOURCE: case GLOSSARYSOURCE: temp = copy_node(list); scratch->notes = cons(temp, scratch->notes); break; case H1: case H2: case H3: case H4: case H5: case H6: if ((list->children->key != AUTOLABEL) && !(scratch->extensions & EXT_NO_LABELS) && !(scratch->extensions & EXT_COMPATIBILITY)) { char *label = label_from_node_tree(list->children); /* create a label from header */ temp = mk_autolink(label); scratch->links = cons(temp, scratch->links); free(label); } break; case TABLE: if (list->children->key != TABLELABEL) { char *label = label_from_node(list->children); /* create a label from header */ temp = mk_autolink(label); scratch->links = cons(temp, scratch->links); free(label); } break; case HEADINGSECTION: case RAW: case LIST: extract_references(list->children, scratch); break; default: break; } list = list->next; } }
int cross_lnk(ARCHD *arcn) { /* * try to make a link to original file (-l flag in copy mode). make sure * we do not try to link to directories in case we are running as root * (and it might succeed). */ if (arcn->type == PAX_DIR) return(1); return(mk_link(arcn->org_name, &(arcn->sb), arcn->name, 1)); }
/* make (or delete) an object in the filesystem */ gboolean mk_obj(FILE * in, char *p, struct rdup * e, GHashTable * uidhash, GHashTable * gidhash) { if (opt_verbose >= 1 && e->f_name) { if (S_ISLNK(e->f_mode) || e->f_lnk) fprintf(stderr, "%s -> %s\n", e->f_name, e->f_target); else fprintf(stderr, "%s\n", e->f_name); } if (opt_table) rdup_write_table(e, stdout); /* split here - or above - return when path is zero length * for links check that the f_size is zero */ switch (e->plusmin) { case MINUS: if (opt_dry || !e->f_name) return TRUE; return rm(e->f_name); case PLUS: /* opt_dry handled within the subfunctions */ /* only files, no hardlinks! */ if (S_ISREG(e->f_mode) && !e->f_lnk) return mk_reg(in, e, uidhash, gidhash); /* no name, we can exit here - for files this is handled * in mk_reg, because we may need to suck in data */ if (e->f_name == NULL) return TRUE; if (S_ISDIR(e->f_mode)) return mk_dir(e, uidhash, gidhash); /* First sym and hardlinks and then regular files */ if (S_ISLNK(e->f_mode) || e->f_lnk) return mk_link(e, p, uidhash, gidhash); if (S_ISBLK(e->f_mode) || S_ISCHR(e->f_mode)) return mk_dev(e, uidhash, gidhash); // There's no way to restore a named socket if (S_ISSOCK(e->f_mode)) return TRUE; if (S_ISFIFO(e->f_mode)) return mk_sock(e, uidhash, gidhash); } /* only reached during the heat death of the universe */ return TRUE; }
int cross_lnk(ARCHD *arcn) { /* * try to make a link to original file (-l flag in copy mode). make * sure we do not try to link to directories in case we are running as * root (and it might succeed). */ if (arcn->type == PAX_DIR) return(1); if (arcn->type == PAX_SLK) { /* for Unix 03 conformance tests 202,203 */ if (!Lflag) return(1); } return(mk_link(arcn->org_name, &(arcn->sb), arcn->name, 1)); }
int lnk_creat(ARCHD *arcn) { struct stat sb; /* * we may be running as root, so we have to be sure that link target * is not a directory, so we lstat and check */ if (lstat(arcn->ln_name, &sb) < 0) { syswarn(1,errno,"Unable to link to %s from %s", arcn->ln_name, arcn->name); return(-1); } if (S_ISDIR(sb.st_mode)) { paxwarn(1, "A hard link to the directory %s is not allowed", arcn->ln_name); return(-1); } if (S_ISLNK(sb.st_mode)) { int res; char buff[PATH_MAX+1]; /* * Conformance: cannot make hard link to symlink - just make a * symlink to the target of the symlink */ if ((res = readlink(arcn->ln_name, buff, sizeof(buff)-1)) < 0) { syswarn(1,errno,"Unable to symlink to %s from %s", arcn->ln_name, arcn->name); return(-1); } buff[res] = 0; res = symlink(buff, arcn->name); return res; } return(mk_link(arcn->ln_name, &sb, arcn->name, 0)); }
int lnk_creat(ARCHD *arcn) { struct stat sb; /* * we may be running as root, so we have to be sure that link target * is not a directory, so we lstat and check */ if (lstat(arcn->ln_name, &sb) < 0) { syswarn(1,errno,"Unable to link to %s from %s", arcn->ln_name, arcn->name); return(-1); } if (S_ISDIR(sb.st_mode)) { paxwarn(1, "A hard link to the directory %s is not allowed", arcn->ln_name); return(-1); } return(mk_link(arcn->ln_name, &sb, arcn->name, 0)); }
/* extract_references -- go through node tree and find elements we need to reference; e.g. links, images, citations, footnotes Remove them from main parse tree */ void extract_references(node *list, scratch_pad *scratch) { /* TODO: Will these all be top level elements? What about RAW?? */ node *temp; node *last = NULL; link_data *l; while (list != NULL) { switch (list->key) { case LINKREFERENCE: l = list->link_data; temp = mk_link(list->children, l->label, l->source, l->title, l->attr); /* store copy of link reference */ scratch->links = cons(temp, scratch->links); /* Disconnect from children so not duplicated */ l->attr = NULL; if (last != NULL) { /* remove this node from tree */ last->next = list->next; free_link_data(list->link_data); free(list); list = last->next; continue; } else { } break; case NOTESOURCE: if (last != NULL) { last->next = list->next; scratch->notes = cons(list, scratch->notes); list = last->next; continue; } break; case GLOSSARYSOURCE: if (last != NULL) { last->next = list->next; scratch->notes = cons(list, scratch->notes); list = last->next; continue; } break; case H1: case H2: case H3: case H4: case H5: case H6: if ((list->children->key != AUTOLABEL) && !(scratch->extensions & EXT_NO_LABELS)) { char *label = label_from_node_tree(list->children); /* create a label from header */ temp = mk_autolink(label); scratch->links = cons(temp, scratch->links); free(label); } break; case TABLE: if (list->children->key != TABLELABEL) { char *label = label_from_node(list->children); /* create a label from header */ temp = mk_autolink(label); scratch->links = cons(temp, scratch->links); free(label); } break; case HEADINGSECTION: extract_references(list->children, scratch); break; default: break; } last = list; list = list->next; } }