Example #1
0
opString opDriver::ToGeneratedPath(const opString& inpath) {
    const opParameters& p = opParameters::Get();

    path adjustedpath = to_relative_path(inpath.GetString());

    // 2. if it's a absolute path, I need to handle the root
    if (adjustedpath.has_root_directory()) {
        // cases: //
        //       /
        //       c:/

        opString pathstring = adjustedpath.string();
        if (pathstring.StartsWith("/")) {
            pathstring = "_root" + pathstring;
        } else if (pathstring.StartsWith("//")) {
            pathstring = "_net" + pathstring.Right(1);
        } else {
            // c:/
            pathstring.Replace(":", "");
            pathstring = "_win/" + pathstring;
        }

        adjustedpath = pathstring.GetString();
    }

    opString adjustedstring = adjustedpath.string();
    adjustedstring.Replace("../", "_/");

    // 3. if it's a complete network path, I need to handle the root
    path newpath =
        p.GeneratedDirectory.GetString() / adjustedstring.GetString();

    return newpath.string();
}
Example #2
0
int cmd_add (int argc, char ** argv, struct mpd_connection *conn )
{
	if (contains_absolute_path(argc, argv) && !path_prepare(conn))
		printErrorAndExit(conn);

	int i;

	if (!mpd_command_list_begin(conn, false))
		printErrorAndExit(conn);

	for(i=0;i<argc;i++) {
		strip_trailing_slash(argv[i]);

		const char *path = argv[i];
		const char *relative_path = to_relative_path(path);
		if (relative_path != NULL)
			path = relative_path;

		if (options.verbosity >= V_VERBOSE)
			printf("adding: %s\n", path);
		mpd_send_add(conn, charset_to_utf8(path));
	}

	if (!mpd_command_list_end(conn))
		printErrorAndExit(conn);

	if (!mpd_response_finish(conn)) {
#if LIBMPDCLIENT_CHECK_VERSION(2,4,0)
		if (mpd_connection_get_error(conn) == MPD_ERROR_SERVER) {
			/* check which of the arguments has failed */
			unsigned location =
				mpd_connection_get_server_error_location(conn);
			if (location < (unsigned)argc) {
				/* we've got a valid location from the
				   server */
				const char *message =
					mpd_connection_get_error_message(conn);
				message = charset_from_utf8(message);
				fprintf(stderr, "error adding %s: %s\n",
					argv[location], message);
				exit(EXIT_FAILURE);
			}
		}
#endif

		printErrorAndExit(conn);
	}

	return 0;
}
Example #3
0
// perform globbing
bool opDriver::GlobMode(const opParameters& p) {
    Globber Globberobj;

    // test settings
    double starttime = opTimer::GetTimeSeconds();

    // TODO: it should print info like...
    // globbing... (if not silent)
    // also..
    // and if no files were found - no files found
    // if no indexes updated -		already up to date
    // if things were updated -		updated indexes

    if (!p.Silent) {
        Log(opString("Globbing to ") +
            to_relative_path(path(p.GeneratedDirectory.GetString())).string() +
            " directory ...");
        Log("");
    }

    bool bResult = false;

    try {
        bResult = Globberobj.Glob(p);
    } catch (boost::filesystem::filesystem_error& fe) {
        opString errorstr = fe.what();
        opString who = "";
        errorstr.Replace(who, "Error: Improper path detected when globbing.");
        Log(errorstr);
    } catch (...) {
        opError::ExceptionError("GlobMode");
    }

    double endtime = opTimer::GetTimeSeconds();

    if (p.Verbose) {
        double totalms = (endtime - starttime) * 1000.0;
        Log(opString("Glob Mode took ") + totalms + " ms");
        Log("");
    }

    if (!bResult && p.Verbose) Log(opString("Glob Mode Failed."));

    return bResult;
}
Example #4
0
File: command.c Project: daaang/mpc
int
cmd_update(int argc, char **argv, struct mpd_connection *conn)
{
	if (contains_absolute_path(argc, argv) && !path_prepare(conn))
		printErrorAndExit(conn);

	if (!mpd_command_list_begin(conn, false))
		printErrorAndExit(conn);

	int i = 0;
	const char *update = "";
	if (argc > 0)
		update = charset_to_utf8(argv[i]);

	do {
		char *tmp = strdup(update);
		strip_trailing_slash(tmp);

		const char *path = tmp;
		const char *relative_path = to_relative_path(path);
		if (relative_path != NULL)
			path = relative_path;

		mpd_send_update(conn, path);
		free(tmp);
	} while (++i < argc && (update = charset_to_utf8(argv[i])) != NULL);

	if (!mpd_command_list_end(conn))
		printErrorAndExit(conn);

	/* obtain the last "update id" response */

	unsigned id = 0;
	while (true) {
		unsigned next_id = mpd_recv_update_id(conn);
		if (next_id == 0)
			break;
		id = next_id;
	}

	my_finishCommand(conn);

	while (options.wait) {
		/* idle until an update finishes */
		enum mpd_idle idle = mpd_run_idle_mask(conn, MPD_IDLE_UPDATE);
		struct mpd_status *status;
		unsigned current_id;

		if (idle == 0)
			printErrorAndExit(conn);

		/* determine the current "update id" */

		status = getStatus(conn);
		current_id = mpd_status_get_update_id(status);
		mpd_status_free(status);

		/* is our last queued update finished now? */

		if (current_id == 0 || current_id > id ||
		    (id > 1 << 30 && id < 1000)) /* wraparound */
			break;
	}

	return 1;
}
Example #5
0
bool opDriver::ValidateDialectFiles(const opParameters& p) {
    /*=== files ===*/

    const vector<opString>& tmpDialects = p.Dialects.GetValues();
    opList<opString> Dialects(tmpDialects.begin(), tmpDialects.end());
    opList<opString>::iterator i = Dialects.Begin();
    opList<opString>::iterator end = Dialects.End();
    opList<opString>::iterator old;

    while (i != end) {
        path filepath = (*i).GetString();

        if (exists(filepath)) {
            filepath = to_relative_path(filepath);
            DohFiles.insert(filepath);
            old = i;
            ++i;
            Dialects.Erase(old);
            continue;
        }

        ++i;
    }

    /*=== files in -d locations ===*/

    const vector<opString>& Dirs = p.Directories.GetValues();

    for (size_t d = 0; d < Dirs.size(); d++) {
        i = Dialects.Begin();
        end = Dialects.End();

        while (i != end) {
            path filepath =
                Dirs[d].GetString() / to_relative_path((*i).GetString());

            if (exists(filepath)) {
                filepath = to_relative_path(filepath);
                DohFiles.insert(filepath);
                old = i;
                ++i;
                Dialects.Erase(old);
                continue;
            }

            ++i;
        }
    }

    /*=== error if files were not found ===*/

    if (!Dialects.IsEmpty()) {
        Log("");
        Log("Error: The following dialects were not found:");

        i = Dialects.Begin();
        end = Dialects.End();

        while (i != end) {
            Log("\t'" + *i + "'");

            ++i;
        }

        Log("");

        return false;
    }

    return true;
}