Esempio n. 1
0
static int
baddel(mmv_t *mmv, REP *p)
{
    HANDLE *hfrom = p->r_hfrom, *hto = p->r_hto;
    FILEINFO *fto = p->r_fdel;
    char *t = fto->fi_name, *f = p->r_ffrom->fi_name;
    char *hnf = hfrom->h_name, *hnt = hto->h_name;

    if (mmv->delstyle == NODEL && !(p->r_flags & R_DELOK) && !(mmv->op & APPEND)) {
        printf("%s%s -> %s%s : old %s%s would have to be %s.\n",
            hnf, f, hnt, t, hnt, t,
            (mmv->op & OVERWRITE) ? "overwritten" : "deleted");
    }
    else if (fto->fi_rep == &mmv->mistake) {
        printf("%s%s -> %s%s : old %s%s was to be done first.\n",
            hnf, f, hnt, t, hnt, t);
    }
    else if (fto->fi_stflags & FI_ISDIR) {
        printf("%s%s -> %s%s : %s%s%s is a directory.\n",
            hnf, f, hnt, t, (mmv->op & APPEND) ? "" : "old ", hnt, t);
    }
    else if ((fto->fi_stflags & FI_NODEL) && !(mmv->op & (APPEND | OVERWRITE))) {
        printf("%s%s -> %s%s : old %s%s lacks delete permission.\n",
            hnf, f, hnt, t, hnt, t);
    }
    else if ((mmv->op & (APPEND | OVERWRITE)) && !fwritable(mmv, hnt, fto)) {
        printf("%s%s -> %s%s : %s%s %s.\n",
            hnf, f, hnt, t, hnt, t, "lacks write permission");
    }
    else {
        return (0);
    }
    ++mmv->badreps;
    return (1);
}
Esempio n. 2
0
static int
skipdel(mmv_t *mmv, REP *p)
{
    if (p->r_flags & R_DELOK) {
        return (0);
    }

    eprintf("%s%s -> %s%s : ",
        p->r_hfrom->h_name, p->r_ffrom->fi_name, p->r_hto->h_name, p->r_nto);

    if (!fwritable(mmv, p->r_hto->h_name, p->r_fdel)) {
        eprintf("old %s%s lacks write permission. delete it",
            p->r_hto->h_name, p->r_nto);
    }
    else {
        eprintf("%s old %s%s",
            (mmv->op & OVERWRITE) ? "overwrite" : "delete",
            p->r_hto->h_name,
            p->r_nto);
    }
    return (!ask_yesno("? ", -1));
}
Esempio n. 3
0
int
main ()
{
  FILE *fp;

  /* Create a file with some contents.  */
  fp = fopen (TESTFILE, "w");
  if (fp == NULL)
    goto skip;
  ASSERT (fwritable (fp));
  if (fwrite ("foobarsh", 1, 8, fp) < 8)
    goto skip;
  ASSERT (fwritable (fp));
  if (fclose (fp))
    goto skip;

  /* Open it in read-only mode.  */
  fp = fopen (TESTFILE, "r");
  if (fp == NULL)
    goto skip;
  ASSERT (!fwritable (fp));
  if (fgetc (fp) != 'f')
    goto skip;
  ASSERT (!fwritable (fp));
  if (fseek (fp, 2, SEEK_CUR))
    goto skip;
  ASSERT (!fwritable (fp));
  if (fgetc (fp) != 'b')
    goto skip;
  ASSERT (!fwritable (fp));
  fflush (fp);
  ASSERT (!fwritable (fp));
  if (fgetc (fp) != 'a')
    goto skip;
  ASSERT (!fwritable (fp));
  if (fseek (fp, 0, SEEK_END))
    goto skip;
  ASSERT (!fwritable (fp));
  if (fclose (fp))
    goto skip;

  /* Open it in read-write mode.  */
  fp = fopen (TESTFILE, "r+");
  if (fp == NULL)
    goto skip;
  ASSERT (fwritable (fp));
  if (fgetc (fp) != 'f')
    goto skip;
  ASSERT (fwritable (fp));
  if (fseek (fp, 2, SEEK_CUR))
    goto skip;
  ASSERT (fwritable (fp));
  if (fgetc (fp) != 'b')
    goto skip;
  ASSERT (fwritable (fp));
  fflush (fp);
  ASSERT (fwritable (fp));
  if (fgetc (fp) != 'a')
    goto skip;
  ASSERT (fwritable (fp));
  if (fputc ('z', fp) != 'z')
    goto skip;
  ASSERT (fwritable (fp));
  if (fseek (fp, 0, SEEK_END))
    goto skip;
  ASSERT (fwritable (fp));
  if (fclose (fp))
    goto skip;

  /* Open it in append mode.  */
  fp = fopen (TESTFILE, "a");
  if (fp == NULL)
    goto skip;
  ASSERT (fwritable (fp));
  if (fwrite ("bla", 1, 3, fp) < 3)
    goto skip;
  ASSERT (fwritable (fp));
  if (fclose (fp))
    goto skip;

  return 0;

 skip:
  fprintf (stderr, "Skipping test: file operations failed.\n");
  return 77;
}