コード例 #1
0
static struct directory *
directory_load_subdir(FILE *fp, struct directory *parent, const char *name,
		      GString *buffer, GError **error_r)
{
	struct directory *directory;
	const char *line;
	bool success;

	if (directory_get_child(parent, name) != NULL) {
		g_set_error(error_r, directory_quark(), 0,
			    "Duplicate subdirectory '%s'", name);
		return NULL;
	}

	if (directory_is_root(parent)) {
		directory = directory_new(name, parent);
	} else {
		char *path = g_strconcat(directory_get_path(parent), "/",
					 name, NULL);
		directory = directory_new(path, parent);
		g_free(path);
	}

	line = read_text_line(fp, buffer);
	if (line == NULL) {
		g_set_error(error_r, directory_quark(), 0,
			    "Unexpected end of file");
		directory_free(directory);
		return NULL;
	}

	if (g_str_has_prefix(line, DIRECTORY_MTIME)) {
		directory->mtime =
			g_ascii_strtoull(line + sizeof(DIRECTORY_MTIME) - 1,
					 NULL, 10);

		line = read_text_line(fp, buffer);
		if (line == NULL) {
			g_set_error(error_r, directory_quark(), 0,
				    "Unexpected end of file");
			directory_free(directory);
			return NULL;
		}
	}

	if (!g_str_has_prefix(line, DIRECTORY_BEGIN)) {
		g_set_error(error_r, directory_quark(), 0,
			    "Malformed line: %s", line);
		directory_free(directory);
		return NULL;
	}

	success = directory_load(fp, directory, buffer, error_r);
	if (!success) {
		directory_free(directory);
		return NULL;
	}

	return directory;
}
コード例 #2
0
ファイル: main.c プロジェクト: khorben/DeforaOS
/* main */
int main(int argc, char * argv[])
{
	int o;
	AppServerOptions options = ASO_LOCAL;
	Event * event;
	Directory * directory;

	while((o = getopt(argc, argv, "LR")) != -1)
		switch(o)
		{
			case 'L':
				options = ASO_LOCAL;
				break;
			case 'R':
				options = ASO_REMOTE;
				break;
			default:
				return _usage();
		}
	if((event = event_new()) == NULL)
		return error_print(PACKAGE) ? 2 : 2;
	if((directory = directory_new(options, event)) == NULL)
	{
		error_print(PACKAGE);
		event_delete(event);
		return 2;
	}
	event_loop(event);
	event_delete(event);
	return 0;
}
コード例 #3
0
ファイル: directory.c プロジェクト: dotpolice/mpd
struct directory *
directory_new_child(struct directory *parent, const char *name_utf8)
{
	assert(holding_db_lock());
	assert(parent != NULL);
	assert(name_utf8 != NULL);
	assert(*name_utf8 != 0);

	char *allocated;
	const char *path_utf8;
	if (directory_is_root(parent)) {
		allocated = NULL;
		path_utf8 = name_utf8;
	} else {
		allocated = g_strconcat(directory_get_path(parent),
					"/", name_utf8, NULL);
		path_utf8 = allocated;
	}

	struct directory *directory = directory_new(path_utf8, parent);
	g_free(allocated);

	list_add_tail(&directory->siblings, &parent->children);
	return directory;
}
static bool
simple_db_open(struct db *_db, G_GNUC_UNUSED GError **error_r)
{
	struct simple_db *db = (struct simple_db *)_db;

	db->root = directory_new("", NULL);
	db->mtime = 0;

	GError *error = NULL;
	if (!simple_db_load(db, &error)) {
		directory_free(db->root);

		g_warning("Failed to load database: %s", error->message);
		g_error_free(error);

		if (!simple_db_check(db, error_r))
			return false;

		db->root = directory_new("", NULL);
	}

	return true;
}
コード例 #5
0
ファイル: directory.c プロジェクト: Intecture/tests
    char *tmp_dirname = mkdtemp(template);
    assert(tmp_dirname);

    char testpath[30];
    strcpy(testpath, tmp_dirname);
    strcat(testpath, "/path/to/dir");
    char mvpath[33];
    strcpy(mvpath, tmp_dirname);
    strcat(mvpath, "/path/to/mv_dir");
    char touchpath[38];
    strcpy(touchpath, mvpath);
    strcat(touchpath, "/test");

    Telemetry telemetry = telemetry_init(&host);

    Directory dir = directory_new(&host, &testpath);
    assert(!directory_exists(&dir, &host));

    DirectoryOpts opts = { .do_recursive = true };

    directory_create(&dir, &host, &opts);
    assert(directory_exists(&dir, &host));
    char create_check_cmd[33];
    strcpy(create_check_cmd, "ls ");
    strcat(create_check_cmd, testpath);
    int create_check = system(create_check_cmd);
    assert(create_check != -1 && WEXITSTATUS(create_check) == 0);

    directory_mv(&dir, &host, &);
    char mv_check_cmd[36];
    strcpy(mv_check_cmd, "ls ");