Exemplo n.º 1
0
static void check_csync_pathes(void **state)
{
    CSYNC *csync = *state;
    int rc;

    _csync_exclude_add( &(csync->excludes), "/exclude" );

    /* Check toplevel dir, the pattern only works for toplevel dir. */
    rc = csync_excluded(csync, "/exclude", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "/foo/exclude", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_NOT_EXCLUDED);

    /* check for a file called exclude. Must still work */
    rc = csync_excluded(csync, "/exclude", CSYNC_FTW_TYPE_FILE);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "/foo/exclude", CSYNC_FTW_TYPE_FILE);
    assert_int_equal(rc, CSYNC_NOT_EXCLUDED);

    /* Add an exclude for directories only: excl/ */
    _csync_exclude_add( &(csync->excludes), "excl/" );
    rc = csync_excluded(csync, "/excl", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "meep/excl", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "meep/excl/file", CSYNC_FTW_TYPE_FILE);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "/excl", CSYNC_FTW_TYPE_FILE);
    assert_int_equal(rc, CSYNC_NOT_EXCLUDED);

    _csync_exclude_add(&csync->excludes, "/excludepath/withsubdir");

    rc = csync_excluded(csync, "/excludepath/withsubdir", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "/excludepath/withsubdir", CSYNC_FTW_TYPE_FILE);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);

    rc = csync_excluded(csync, "/excludepath/withsubdir2", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_NOT_EXCLUDED);

    rc = csync_excluded(csync, "/excludepath/withsubdir/foo", CSYNC_FTW_TYPE_DIR);
    assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
}
Exemplo n.º 2
0
static void check_csync_exclude_add(void **state)
{
    CSYNC *csync = *state;

    _csync_exclude_add(csync, (const char *) "/tmp/check_csync1/*");
    assert_string_equal(csync->excludes->vector[0], "/tmp/check_csync1/*");
}
Exemplo n.º 3
0
int csync_exclude_load(CSYNC *ctx, const char *fname) {
  int fd = -1;
  int i = 0;
  int rc = -1;
  off_t size;
  char *buf = NULL;
  char *entry = NULL;

#ifdef _WIN32
  _fmode = _O_BINARY;  
#endif
  fd = open(fname, O_RDONLY);
  if (fd < 0) {
    return -1;
  }

  size = lseek(fd, 0, SEEK_END);
  if (size < 0) {
    rc = -1;
    goto out;
  }
  lseek(fd, 0, SEEK_SET);
  if (size == 0) {
    rc = 0;
    goto out;
  }
  buf = c_malloc(size);
  if (read(fd, buf, size) != size) {
    rc = -1;
    goto out;
  }
  close(fd);

  /* FIXME: Don't add duplicates */
  entry = buf;
  for (i = 0; i < size; i++) {
    if (buf[i] == '\n') {
      if (entry != buf + i) {
        buf[i] = '\0';
        if (*entry != '#' || *entry == '\n') {
          CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Adding entry: %s", entry);
          _csync_exclude_add(ctx, entry);
        }
      }
      entry = buf + i + 1;
    }
  }
  SAFE_FREE(buf);

  rc = 0;
out:
  SAFE_FREE(buf);
  close(fd);
  return rc;
}
Exemplo n.º 4
0
static void setup_init(void **state) {
    CSYNC *csync;
    int rc;

    csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");

    rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes));
    assert_int_equal(rc, 0);

    /* and add some unicode stuff */
    rc = _csync_exclude_add(&(csync->excludes), "*.💩");
    assert_int_equal(rc, 0);
    rc = _csync_exclude_add(&(csync->excludes), "пятницы.*");
    assert_int_equal(rc, 0);
    rc = _csync_exclude_add(&(csync->excludes), "*/*.out");
    assert_int_equal(rc, 0);
    rc = _csync_exclude_add(&(csync->excludes), "latex*/*.run.xml");
    assert_int_equal(rc, 0);
    rc = _csync_exclude_add(&(csync->excludes), "latex/*/*.tex.tmp");
    assert_int_equal(rc, 0);

    *state = csync;
}
Exemplo n.º 5
0
int csync_exclude_load(const char *fname, c_strlist_t **list) {
  int fd = -1;
  int i = 0;
  int rc = -1;
  int64_t size;
  char *buf = NULL;
  char *entry = NULL;
  mbchar_t *w_fname;

  if (fname == NULL) {
      return -1;
  }

#ifdef _WIN32
  _fmode = _O_BINARY;
#endif

  w_fname = c_utf8_path_to_locale(fname);
  if (w_fname == NULL) {
      return -1;
  }

  fd = _topen(w_fname, O_RDONLY);
  c_free_locale_string(w_fname);
  if (fd < 0) {
    return -1;
  }

  size = lseek(fd, 0, SEEK_END);
  if (size < 0) {
    rc = -1;
    goto out;
  }
  lseek(fd, 0, SEEK_SET);
  if (size == 0) {
    rc = 0;
    goto out;
  }
  buf = c_malloc(size + 1);
  if (read(fd, buf, size) != size) {
    rc = -1;
    goto out;
  }
  buf[size] = '\0';

  /* FIXME: Use fgets and don't add duplicates */
  entry = buf;
  for (i = 0; i < size; i++) {
    if (buf[i] == '\n' || buf[i] == '\r') {
      if (entry != buf + i) {
        buf[i] = '\0';
        if (*entry != '#') {
          const char *unescaped = csync_exclude_expand_escapes(entry);
          rc = _csync_exclude_add(list, unescaped);
          if( rc == 0 ) {
              CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Adding entry: %s", unescaped);
          }
          SAFE_FREE(unescaped);
          if (rc < 0) {
              goto out;
          }
        }
      }
      entry = buf + i + 1;
    }
  }

  rc = 0;
out:
  SAFE_FREE(buf);
  close(fd);
  return rc;
}