Example #1
0
int main(int argc, char **argv) {
  if (argc < 2) {
    print_usage();
    return 1;
  }
  std::string cmd = argv[1];

  // If there are files specified as part of the command
  // collect them into a vector.
  std::vector<std::string> files(argv + 2, argv + argc);

  uid_t euid = geteuid();
  auto print_spooler = spool_controller();

  if (cmd == ADD)
    print_spooler.add_files(files);
  else if (cmd == RM)
    print_spooler.rm_files(files);
  else if (cmd == LS)
    print_spooler.ls_files();
  else
    print_usage();

  // We restore the euid because spool_info's destructor needs it so that it
  // can write the info file back into its place within the spool directory.
  seteuid(euid);
  return 0;
}
void FileSet::add_path_to_source(const std::string& path)
{
	std::set<std::string> exts;
	exts.insert(get_config().get_header_extensions().begin(), get_config().get_header_extensions().end());
	exts.insert(get_config().get_source_extensions().begin(), get_config().get_source_extensions().end());
	add_files(path, exts);
}
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
{
	char buf[10+IFNAMSIZ];

	sprintf(buf, "netdev:%s", sdata->name);
	sdata->debugfs.dir = debugfs_create_dir(buf,
		sdata->local->hw.wiphy->debugfsdir);
	add_files(sdata);
}
Example #4
0
File: fb.c Project: gettler/mvpmc
int
fb_update(mvp_widget_t *fb)
{
	mvpw_show(root);
	mvpw_expose(root);

	mvpw_clear_menu(fb);
	mvpw_set_menu_title(fb, cwd);

	busy_start();
	if (strstr(cwd,"/uPnP")!=NULL ){
		mount_djmount(cwd);
	}
	add_dirs(fb);
	add_files(fb);
	busy_end();

	return 0;
}
Example #5
0
File: add.c Project: 13leaf/git
int cmd_add(int argc, const char **argv, const char *prefix)
{
	int exit_status = 0;
	int newfd;
	struct pathspec pathspec;
	struct dir_struct dir;
	int flags;
	int add_new_files;
	int require_pathspec;
	char *seen = NULL;
	int implicit_dot = 0;
	struct update_callback_data update_data;

	git_config(add_config, NULL);

	argc = parse_options(argc, argv, prefix, builtin_add_options,
			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
	if (patch_interactive)
		add_interactive = 1;
	if (add_interactive)
		exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));

	if (edit_interactive)
		return(edit_patch(argc, argv, prefix));
	argc--;
	argv++;

	if (0 <= addremove_explicit)
		addremove = addremove_explicit;
	else if (take_worktree_changes && ADDREMOVE_DEFAULT)
		addremove = 0; /* "-u" was given but not "-A" */

	if (addremove && take_worktree_changes)
		die(_("-A and -u are mutually incompatible"));

	/*
	 * Warn when "git add pathspec..." was given without "-u" or "-A"
	 * and pathspec... covers a removed path.
	 */
	memset(&update_data, 0, sizeof(update_data));
	if (!take_worktree_changes && addremove_explicit < 0)
		update_data.warn_add_would_remove = 1;

	if (!take_worktree_changes && addremove_explicit < 0 && argc)
		/*
		 * Turn "git add pathspec..." to "git add -A pathspec..."
		 * in Git 2.0 but not yet
		 */
		; /* addremove = 1; */

	if (!show_only && ignore_missing)
		die(_("Option --ignore-missing can only be used together with --dry-run"));
	if (addremove) {
		option_with_implicit_dot = "--all";
		short_option_with_implicit_dot = "-A";
	}
	if (take_worktree_changes) {
		option_with_implicit_dot = "--update";
		short_option_with_implicit_dot = "-u";
	}
	if (option_with_implicit_dot && !argc) {
		static const char *here[2] = { ".", NULL };
		argc = 1;
		argv = here;
		implicit_dot = 1;
	}

	add_new_files = !take_worktree_changes && !refresh_only;
	require_pathspec = !take_worktree_changes;

	newfd = hold_locked_index(&lock_file, 1);

	flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
		 (show_only ? ADD_CACHE_PRETEND : 0) |
		 (intent_to_add ? ADD_CACHE_INTENT : 0) |
		 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
		 (!(addremove || take_worktree_changes)
		  ? ADD_CACHE_IGNORE_REMOVAL : 0)) |
		 (implicit_dot ? ADD_CACHE_IMPLICIT_DOT : 0);

	if (require_pathspec && argc == 0) {
		fprintf(stderr, _("Nothing specified, nothing added.\n"));
		fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n"));
		return 0;
	}

	if (read_cache() < 0)
		die(_("index file corrupt"));

	/*
	 * Check the "pathspec '%s' did not match any files" block
	 * below before enabling new magic.
	 */
	parse_pathspec(&pathspec, 0,
		       PATHSPEC_PREFER_FULL |
		       PATHSPEC_SYMLINK_LEADING_PATH |
		       PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE,
		       prefix, argv);

	if (add_new_files) {
		int baselen;
		struct pathspec empty_pathspec;

		/* Set up the default git porcelain excludes */
		memset(&dir, 0, sizeof(dir));
		if (!ignored_too) {
			dir.flags |= DIR_COLLECT_IGNORED;
			setup_standard_excludes(&dir);
		}

		memset(&empty_pathspec, 0, sizeof(empty_pathspec));
		/* This picks up the paths that are not tracked */
		baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
		if (pathspec.nr)
			seen = prune_directory(&dir, &pathspec, baselen,
					implicit_dot ? WARN_IMPLICIT_DOT : 0);
	}

	if (refresh_only) {
		refresh(verbose, &pathspec);
		goto finish;
	}
	if (implicit_dot && prefix)
		refresh_cache(REFRESH_QUIET);

	if (pathspec.nr) {
		int i;

		if (!seen)
			seen = find_pathspecs_matching_against_index(&pathspec);

		/*
		 * file_exists() assumes exact match
		 */
		GUARD_PATHSPEC(&pathspec,
			       PATHSPEC_FROMTOP |
			       PATHSPEC_LITERAL |
			       PATHSPEC_GLOB |
			       PATHSPEC_ICASE);

		for (i = 0; i < pathspec.nr; i++) {
			const char *path = pathspec.items[i].match;
			if (!seen[i] &&
			    ((pathspec.items[i].magic &
			      (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
			     !file_exists(path))) {
				if (ignore_missing) {
					int dtype = DT_UNKNOWN;
					if (is_excluded(&dir, path, &dtype))
						dir_add_ignored(&dir, path, pathspec.items[i].len);
				} else
					die(_("pathspec '%s' did not match any files"),
					    pathspec.items[i].original);
			}
		}
		free(seen);
	}

	plug_bulk_checkin();

	if ((flags & ADD_CACHE_IMPLICIT_DOT) && prefix) {
		/*
		 * Check for modified files throughout the worktree so
		 * update_callback has a chance to warn about changes
		 * outside the cwd.
		 */
		update_data.implicit_dot = prefix;
		update_data.implicit_dot_len = strlen(prefix);
		free_pathspec(&pathspec);
		memset(&pathspec, 0, sizeof(pathspec));
	}
	update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT;
	update_files_in_cache(prefix, &pathspec, &update_data);

	exit_status |= !!update_data.add_errors;
	if (add_new_files)
		exit_status |= add_files(&dir, flags);

	unplug_bulk_checkin();

finish:
	if (active_cache_changed) {
		if (write_cache(newfd, active_cache, active_nr) ||
		    commit_locked_index(&lock_file))
			die(_("Unable to write new index file"));
	}

	return exit_status;
}
Example #6
0
int
notmuch_new_command (void *ctx, int argc, char *argv[])
{
    notmuch_config_t *config;
    notmuch_database_t *notmuch;
    add_files_state_t add_files_state;
    double elapsed;
    struct timeval tv_now, tv_start;
    int ret = 0;
    struct stat st;
    const char *db_path;
    char *dot_notmuch_path;
    struct sigaction action;
    _filename_node_t *f;
    int renamed_files, removed_files;
    notmuch_status_t status;
    int i;
    notmuch_bool_t timer_is_active = FALSE;

    add_files_state.verbose = 0;
    add_files_state.output_is_a_tty = isatty (fileno (stdout));

    for (i = 0; i < argc && argv[i][0] == '-'; i++) {
	if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
	    add_files_state.verbose = 1;
	} else {
	    fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
	    return 1;
	}
    }
    config = notmuch_config_open (ctx, NULL, NULL);
    if (config == NULL)
	return 1;

    add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
    add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
    add_files_state.message_ids_to_sync = _filename_list_create (ctx);
    db_path = notmuch_config_get_database_path (config);

    dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");

    if (stat (dot_notmuch_path, &st)) {
	int count;

	count = 0;
	count_files (db_path, &count);
	if (interrupted)
	    return 1;

	printf ("Found %d total files (that's not much mail).\n", count);
	notmuch = notmuch_database_create (db_path);
	add_files_state.total_files = count;
    } else {
	notmuch = notmuch_database_open (db_path,
					 NOTMUCH_DATABASE_MODE_READ_WRITE);
	if (notmuch == NULL)
	    return 1;

	if (notmuch_database_needs_upgrade (notmuch)) {
	    printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");
	    gettimeofday (&add_files_state.tv_start, NULL);
	    notmuch_database_upgrade (notmuch, upgrade_print_progress,
				      &add_files_state);
	    printf ("Your notmuch database has now been upgraded to database format version %u.\n",
		    notmuch_database_get_version (notmuch));
	}

	add_files_state.total_files = 0;
    }

    if (notmuch == NULL)
	return 1;

    /* Setup our handler for SIGINT. We do this after having
     * potentially done a database upgrade we this interrupt handler
     * won't support. */
    memset (&action, 0, sizeof (struct sigaction));
    action.sa_handler = handle_sigint;
    sigemptyset (&action.sa_mask);
    action.sa_flags = SA_RESTART;
    sigaction (SIGINT, &action, NULL);

    talloc_free (dot_notmuch_path);
    dot_notmuch_path = NULL;

    add_files_state.processed_files = 0;
    add_files_state.added_messages = 0;
    gettimeofday (&add_files_state.tv_start, NULL);

    add_files_state.removed_files = _filename_list_create (ctx);
    add_files_state.removed_directories = _filename_list_create (ctx);

    if (! debugger_is_active () && add_files_state.output_is_a_tty
	&& ! add_files_state.verbose) {
	setup_progress_printing_timer ();
	timer_is_active = TRUE;
    }

    ret = add_files (notmuch, db_path, &add_files_state);

    removed_files = 0;
    renamed_files = 0;
    gettimeofday (&tv_start, NULL);
    for (f = add_files_state.removed_files->head; f; f = f->next) {
	status = notmuch_database_remove_message (notmuch, f->filename);
	if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
	    renamed_files++;
	else
	    removed_files++;
	if (do_print_progress) {
	    do_print_progress = 0;
	    generic_print_progress ("Cleaned up", "messages",
		tv_start, removed_files + renamed_files,
		add_files_state.removed_files->count);
	}
    }

    gettimeofday (&tv_start, NULL);
    for (f = add_files_state.removed_directories->head, i = 0; f; f = f->next, i++) {
	_remove_directory (ctx, notmuch, f->filename,
			   &renamed_files, &removed_files);
	if (do_print_progress) {
	    do_print_progress = 0;
	    generic_print_progress ("Cleaned up", "directories",
		tv_start, i,
		add_files_state.removed_directories->count);
	}
    }

    talloc_free (add_files_state.removed_files);
    talloc_free (add_files_state.removed_directories);

    /* Now that removals are done (hence the database is aware of all
     * renames), we can synchronize maildir_flags to tags for all
     * messages that had new filenames appear on this run. */
    gettimeofday (&tv_start, NULL);
    if (add_files_state.synchronize_flags) {
	_filename_node_t *node;
	notmuch_message_t *message;
	for (node = add_files_state.message_ids_to_sync->head, i = 0;
	     node;
	     node = node->next, i++)
	{
	    message = notmuch_database_find_message (notmuch, node->filename);
	    notmuch_message_maildir_flags_to_tags (message);
	    notmuch_message_destroy (message);
	    if (do_print_progress) {
		do_print_progress = 0;
		generic_print_progress (
		    "Synchronized tags for", "messages",
		    tv_start, i, add_files_state.message_ids_to_sync->count);
	    }
	}
    }

    talloc_free (add_files_state.message_ids_to_sync);
    add_files_state.message_ids_to_sync = NULL;

    if (timer_is_active)
	stop_progress_printing_timer ();

    gettimeofday (&tv_now, NULL);
    elapsed = notmuch_time_elapsed (add_files_state.tv_start,
				    tv_now);

    if (add_files_state.processed_files) {
	printf ("Processed %d %s in ", add_files_state.processed_files,
		add_files_state.processed_files == 1 ?
		"file" : "total files");
	notmuch_time_print_formatted_seconds (elapsed);
	if (elapsed > 1) {
	    printf (" (%d files/sec.).\033[K\n",
		    (int) (add_files_state.processed_files / elapsed));
	} else {
	    printf (".\033[K\n");
	}
    }

    if (add_files_state.added_messages) {
	printf ("Added %d new %s to the database.",
		add_files_state.added_messages,
		add_files_state.added_messages == 1 ?
		"message" : "messages");
    } else {
	printf ("No new mail.");
    }

    if (removed_files) {
	printf (" Removed %d %s.",
		removed_files,
		removed_files == 1 ? "message" : "messages");
    }

    if (renamed_files) {
	printf (" Detected %d file %s.",
		renamed_files,
		renamed_files == 1 ? "rename" : "renames");
    }

    printf ("\n");

    if (ret) {
	printf ("\nNote: At least one error was encountered: %s\n",
		notmuch_status_to_string (ret));
    }

    notmuch_database_close (notmuch);

    return ret || interrupted;
}
Example #7
0
int cmd_add(int argc, const char **argv, const char *prefix)
{
	int exit_status = 0;
	int newfd;
	const char **pathspec;
	struct dir_struct dir;
	int flags;
	int add_new_files;
	int require_pathspec;

	argc = parse_options(argc, argv, builtin_add_options,
			  builtin_add_usage, 0);
	if (patch_interactive)
		add_interactive = 1;
	if (add_interactive)
		exit(interactive_add(argc, argv, prefix));

	git_config(add_config, NULL);

	if (addremove && take_worktree_changes)
		die("-A and -u are mutually incompatible");
	if ((addremove || take_worktree_changes) && !argc) {
		static const char *here[2] = { ".", NULL };
		argc = 1;
		argv = here;
	}

	add_new_files = !take_worktree_changes && !refresh_only;
	require_pathspec = !take_worktree_changes;

	newfd = hold_locked_index(&lock_file, 1);

	flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
		 (show_only ? ADD_CACHE_PRETEND : 0) |
		 (intent_to_add ? ADD_CACHE_INTENT : 0) |
		 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
		 (!(addremove || take_worktree_changes)
		  ? ADD_CACHE_IGNORE_REMOVAL : 0));

	if (require_pathspec && argc == 0) {
		fprintf(stderr, "Nothing specified, nothing added.\n");
		fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
		return 0;
	}
	pathspec = validate_pathspec(argc, argv, prefix);

	if (read_cache() < 0)
		die("index file corrupt");
	treat_gitlinks(pathspec);

	if (add_new_files)
		/* This picks up the paths that are not tracked */
		fill_directory(&dir, pathspec, ignored_too);

	if (refresh_only) {
		refresh(verbose, pathspec);
		goto finish;
	}

	exit_status |= add_files_to_cache(prefix, pathspec, flags);

	if (add_new_files)
		exit_status |= add_files(&dir, flags);

 finish:
	if (active_cache_changed) {
		if (write_cache(newfd, active_cache, active_nr) ||
		    commit_locked_index(&lock_file))
			die("Unable to write new index file");
	}

	return exit_status;
}
Example #8
0
int
main(int argc, char *argv[])
{
  char *revdb_file = "revdb";
  char *verdb_file = "verdb";
  char *version_file = "VERSION";
  char *output_file = "version.c";
  char *build_file = ".build";
  int   i = 1, r;
  unsigned long summ = 0, oldsumm;
  int major, minor;
  int revsumm, patch;
  int enable_new_version = 0;
  int disable_patch_inc = 0;
  int has_norev = 0;
  int build;
  int use_cvs = 0;
  int do_not_commit_revdb = 0;

  if (argc == 1) report_usage();

  while (1) {
    if (!strcmp(argv[i], "-r")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-r' expects an argument\n");
        exit(1);
      }
      revdb_file = argv[i++];
    } else if (!strcmp(argv[i], "-d")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-d' expects an argument\n");
        exit(1);
      }
      verdb_file = argv[i++];
    } else if (!strcmp(argv[i], "-v")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-v' expects an argument\n");
        exit(1);
      }
      version_file = argv[i++];
    } else if (!strcmp(argv[i], "-V")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-V' expects an argument\n");
        exit(1);
      }
      version_file = 0;
      strcpy(major_version, argv[i++]);
    } else if (!strcmp(argv[i], "-b")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-b' expects an argument\n");
        exit(1);        
      }
      build_file = argv[i++];
    } else if (!strcmp(argv[i], "-P")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-P' expects an argument\n");
        exit(1);        
      }
      variable_prefix = argv[i++];
    } else if (!strcmp(argv[i], "-o")) {
      if (++i >= argc) {
        fprintf(stderr, "option '-o' expects an argument\n");
        exit(1);        
      }
      output_file = argv[i++];
    } else if (!strcmp(argv[i], "-n")) {
      i++;
      enable_new_version = 1;
    } else if (!strcmp(argv[i], "-p")) {
      i++;
      disable_patch_inc = 1;
    } else if (!strcmp(argv[i], "-C")) {
      i++;
      use_cvs = 1;
    } else if (!strcmp(argv[i], "-S")) {
      i++;
      svn_mode = 1;
    } else if (!strcmp(argv[i], "-x")) {
      i++;
      do_not_commit_revdb = 1;
    } else {
      break;
    }
  }
  if (i >= argc) report_usage();

  if (getenv("REVINFO_NO_COMMIT")) do_not_commit_revdb = 1;

  if (version_file) read_version(version_file);
  read_revdb(revdb_file);
  read_verdb(verdb_file);

  for (; i < argc; i++) {
    r = scan_file(argv[i], &major, &minor, &summ);
    if (r < 0) return 1; /* FIXME: is it ok? */
    if (r == 0) {
      /* no revision information */
      add_files(argv[i], 0, 0, 1);
      has_norev = 1;
    } else {
      add_files(argv[i], major, minor, 0);
      r = lookup_revdb(argv[i], major, minor, &oldsumm);
      if (!r) {
        fprintf(stderr,"%s,v %d.%d not in database\n",
                argv[i], major, minor);
        add_revdb_entry(argv[i], major, minor, summ);
        revdb_updated = 1;
      } else {
        if (summ != oldsumm) {
          fprintf(stderr,"%s,v %d.%d is modified\n",
                  argv[i], major, minor);
          has_modified = 1;
        }
      }
    }
  }

  /* scan for missing files */
  for (i = 0; i < revdb_u; i++) {
    int j, max_major, max_minor, f_major, f_minor, f_norev;

    if (revdb[i].flag) continue; /* already seen */
    revdb[i].flag = 1;
    max_major = revdb[i].major;
    max_minor = revdb[i].minor;
    for (j = i + 1; j < revdb_u; j++) {
      if (revdb[j].flag) continue;
      if (strcmp(revdb[i].file, revdb[j].file)) continue;
      revdb[j].flag = 1;
      if (revdb[j].major > max_major) {
        max_major = revdb[j].major;
        max_minor = revdb[j].minor;
      } else if (revdb[j].major == max_major && revdb[j].minor > max_minor) {
        max_minor = revdb[j].minor;
      }
    }

    if (!lookup_files(revdb[i].file, &f_major, &f_minor, &f_norev)) {
      fprintf(stderr, "%s,v %d.%d deleted?\n",
              revdb[i].file, max_major, max_minor);
      //return 1;                 /* FIXME */
    } else {
      if (f_norev) {
        fprintf(stderr, "%s,v %d.%d replaced with new file?\n",
                revdb[i].file, max_major, max_minor);
        return 1;               /* FIXME */
      }
      if (f_major < max_major
          || (f_major == max_major && f_minor < max_minor)) {
        fprintf(stderr, "%s,v %d.%d decreased revision number\n",
                revdb[i].file, max_major, max_minor);
        return 1;               /* FIXME */
      }
    }
  }

  /* calculate revision summ */
  if (svn_mode) {
    revsumm = -1;
    for (i = 0; i < files_u; i++) {
      if (!files[i].norev && revsumm < files[i].major)
        revsumm = files[i].major;
    }
    if (revdb_major > revsumm) revsumm = revdb_major;
    printf("max revision: %d\n", revsumm);
  } else {
    revsumm = 0;
    for (i = 0; i < files_u; i++) {
      if (files[i].norev) { /*revsumm++;*/ }
      else revsumm += files[i].major + files[i].minor;
    }
    printf("revision summ: %d\n", revsumm);
  }

  if (!lookup_verdb(major_version, revsumm, &patch) && patch == -1
      && !enable_new_version) {
    strcat(major_version, "pre");
    enable_new_version = 1;
  }

  if (!lookup_verdb(major_version, revsumm, &patch)) {
    /* no version corresponds to the given revsumm */
    if (patch == -1) {
      /* don't even have this major */
      if (has_modified || has_norev || disable_patch_inc) {
        /* probably we're in preparation for new version */
        /* delay new version until files are checked in */
        read_build(build_file, &build);
        build++;
        write_build(build_file, build);
        sprintf(version_string, "<new version> #%d", build);
      } else {
        patch = first_patch(major_version);
        add_verdb(major_version, patch, revsumm, time(0));
        verdb_updated = 1;
        write_build(build_file, 0);
        make_full_version(major_version, patch);
        sprintf(version_string, "%s", full_version);
      }
    } else {
      if (!has_modified && !has_norev && disable_patch_inc
          && use_cvs && svn_mode) {
        write_build(build_file, 0);
        make_full_version(major_version, patch);
        sprintf(version_string, "%s+ (SVN r%d)", full_version, revsumm);
      } else if ((has_modified || has_norev)
                 && disable_patch_inc && use_cvs && svn_mode) {
        read_build(build_file, &build);
        build++;
        write_build(build_file, build);
        make_full_version(major_version, patch);
        sprintf(version_string, "%s+ (SVN r%d) #%d", full_version, revsumm,
                build);
      } else if (has_modified || has_norev || disable_patch_inc) {
        read_build(build_file, &build);
        build++;
        write_build(build_file, build);
        make_full_version(major_version, patch);
        sprintf(version_string, "%s #%d", full_version, build);
      } else {
        /* increase a minor */
        patch++;
        add_verdb(major_version, patch, revsumm, time(0));
        verdb_updated = 1;
        write_build(build_file, 0);
        make_full_version(major_version, patch);
        sprintf(version_string, "%s", full_version);
      }
    }
  } else {
    if (has_modified || has_norev) {
      /* a modified version */
      read_build(build_file, &build);
      build++;
      write_build(build_file, build);
      make_full_version(major_version, patch);
      sprintf(version_string, "%s #%d", full_version, build);
    } else {
      /* got stock version */
      make_full_version(major_version, patch);
      sprintf(version_string, "%s", full_version);
    }
  }

  write_output(output_file);
  if (revdb_updated) {
    write_revdb(revdb_file);
    if (use_cvs && !do_not_commit_revdb) {
      if (svn_mode) {
        sprintf(cmdline, "svn ci -m \"\" %s", revdb_file);
      } else {
        sprintf(cmdline, "cvs ci -m \"\" %s", revdb_file);
      }
      printf("doing: %s\n", cmdline);
      system(cmdline);
    }
  }
  if (verdb_updated) {
    write_verdb(verdb_file);
    if (use_cvs) {
      if (svn_mode) {
        sprintf(cmdline, "svn ci -m \"\" %s", verdb_file);
      } else {
        sprintf(cmdline, "cvs ci -m \"\" %s", verdb_file);
      }
      printf("doing: %s\n", cmdline);
      system(cmdline);
    }
  }

  return 0;
}
Example #9
0
int main(int argc, char *argv[]) 
{
	argv0 = argv[0];
	shrc rc;
			
	// htmllabel stree:initcall
	// initialize connection to server
	SH_DO(Shore::init(argc, argv, 0, getenv("DOC_INDEX_RC")));

	// get command-line options
	int c;
	while ((c = getopt(argc,argv,"aldpV")) != EOF) switch(c) {
		case 'a': operation = OP_ADD; break;
		case 'l': operation = OP_LIST; break;
		case 'd': operation = OP_DEL; break;
		case 'p': operation = OP_POOL_LIST; break;
		case 'V': verbose++; break;
		default: usage();
	}

	if (operation == OP_NONE)
		usage();

	// Start a transaction for initialization
	SH_BEGIN_TRANSACTION(rc);
	if (rc)
		rc.fatal(); // this terminates the program with extreme prejudice

	// Check that our demo directory exists
	rc = Shore::chdir(DEMO_DIR);
	if (rc != RCOK) {
		if (rc != RC(SH_NotFound))
			SH_ABORT_TRANSACTION(rc);

		// Not found.  Must be the first time through.
		// Create the directory
		SH_DO(Shore::mkdir(DEMO_DIR, 0755));
		SH_DO(Shore::chdir(DEMO_DIR));

		// htmllabel stree:createrepository
		// Make a new DocIndex object ...
		repository = new("repository", 0644) DocIndex;
		repository.update()->initialize();

		// ... and a pool for allocating Nodes.
		SH_DO(nodes.create_pool("pool", 0644, nodes));
	} else { // not first time

		// Get the repository root from the database ...
		SH_DO(Ref<DocIndex>::lookup("repository",repository));

		// ... and the pool for creating nodes
		SH_DO(nodes.lookup("pool", nodes));
	}

	SH_DO(SH_COMMIT_TRANSACTION);

	switch (operation) {
		case OP_ADD:
			add_files(argc-optind, argv+optind);
			break;
		case OP_LIST:
			if (optind != argc-1)
				usage();
			list_files(argv[optind]);
			break;
		case OP_DEL:
			delete_files(argc-optind, argv+optind);
			break;
		case OP_POOL_LIST:
			pool_list();
			break;
		default: break;
	}

	return 0;
} // main
Example #10
0
	bool make( std::string target_file, std::string outfile
		, ErrorHandler error_handler
		, ProgressHandler print_progress
		, std::vector<std::string> const & web_seeds, std::vector<std::string> & trackers
		, bool use_merklefile /*= false*/, std::string root_cert /*= ""*/
		, int pad_file_limit /*= -1*/, int piece_size /*= 0*/, bool inc_sha1_hash /*= true*/
		, bool dont_follow_symlinks /*= false*/ )
	{
		char const* creator_str = "libtorrent";

		int flags = 0;

#ifndef BOOST_NO_EXCEPTIONS
		try
		{
#endif
			std::string merklefile;

			if( use_merklefile )
			{
				merklefile = outfile + "_mkl";
				flags |= create_torrent::merkle;
			}

			if( inc_sha1_hash )
			{
				flags |= create_torrent::calculate_file_hashes;
			}

			if( pad_file_limit > 0 )
			{
				flags |= create_torrent::optimize;
			}

			if( dont_follow_symlinks )
			{
				flags |= create_torrent::symlinks;
			}

			if( trackers.empty() )
			{
				trackers.push_back( "udp://tracker.openbittorrent.com:80/announce" );
				trackers.push_back( "udp://tracker.publicbt.com:80/announce" );
			}

			file_storage fs;
			file_pool fp;
			std::string full_path = libtorrent::complete( target_file );

			add_files(fs, full_path, [](std::string const& f)->bool
			{
				if (filename(f)[0] == '.') return false;
				//fprintf(stderr, "%s\n", f.c_str());
				return true;
			}
			, flags);

			if (fs.num_files() == 0)
			{
				error_handler( 0, "no target files specified.\n" );
				return false;
			}

			create_torrent t(fs, piece_size, pad_file_limit, flags);

			int tracker_count = 0;

			for (auto i = trackers.begin(); i != trackers.end(); ++i)
				t.add_tracker(*i, tracker_count++);

			for (auto i = web_seeds.begin(); i != web_seeds.end(); ++i)
			{
				//if( i->find( "http" ) == 0 )
				//	t.add_http_seed(*i);
				//else
				t.add_url_seed(*i);
			}

			error_code ec;
			set_piece_hashes(t, parent_path(full_path)
				, boost::bind(print_progress, _1, t.num_pieces()), ec);

			if (ec)
			{
				error_handler( 1, ec.message().c_str() );
				return false;
			}

			t.set_creator(creator_str);

			if (!root_cert.empty())
			{
				std::vector<char> pem;
				load_file(root_cert, pem, ec, 10000);
				if (ec)
				{
					error_handler( 2, (ec.message() + ": failed to load root certificate for tracker.").c_str() );
					return false;
				}
				else
				{
					t.set_root_cert(std::string(&pem[0], pem.size()));
				}
			}

			// create the torrent and print it to stdout
			std::vector<char> torrent;
			bencode(back_inserter(torrent), t.generate());
			FILE* output = stdout;
			if (!outfile.empty())
				output = fopen(outfile.c_str(), "wb+");
			fwrite(&torrent[0], 1, torrent.size(), output);

			if (output != stdout)
				fclose(output);

			if (!merklefile.empty())
			{
				output = fopen(merklefile.c_str(), "wb+");
				int ret = fwrite(&t.merkle_tree()[0], 20, t.merkle_tree().size(), output);
				if (ret != t.merkle_tree().size() * 20)
				{
					error_handler( 3, (merklefile + " : failed to write.").c_str() );
					fclose(output);
					return false;
				}				
			}

			fclose(output);

#ifndef BOOST_NO_EXCEPTIONS
		}
		catch (std::exception& e)
		{
			error_handler( 4, e.what() );
			return false;
		}
#endif
		return true;
	}
Example #11
0
int cmd_add(int argc, const char **argv, const char *prefix)
{
	int exit_status = 0;
	int newfd;
	const char **pathspec;
	struct dir_struct dir;
	int flags;
	int add_new_files;
	int require_pathspec;
	char *seen = NULL;

	git_config(add_config, NULL);

	argc = parse_options(argc, argv, prefix, builtin_add_options,
			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
	if (patch_interactive)
		add_interactive = 1;
	if (add_interactive)
		exit(interactive_add(argc - 1, argv + 1, prefix));

	if (edit_interactive)
		return(edit_patch(argc, argv, prefix));
	argc--;
	argv++;

	if (addremove && take_worktree_changes)
		die("-A and -u are mutually incompatible");
	if (!show_only && ignore_missing)
		die("Option --ignore-missing can only be used together with --dry-run");
	if ((addremove || take_worktree_changes) && !argc) {
		static const char *here[2] = { ".", NULL };
		argc = 1;
		argv = here;
	}

	add_new_files = !take_worktree_changes && !refresh_only;
	require_pathspec = !take_worktree_changes;

	newfd = hold_locked_index(&lock_file, 1);

	flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
		 (show_only ? ADD_CACHE_PRETEND : 0) |
		 (intent_to_add ? ADD_CACHE_INTENT : 0) |
		 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
		 (!(addremove || take_worktree_changes)
		  ? ADD_CACHE_IGNORE_REMOVAL : 0));

	if (require_pathspec && argc == 0) {
		fprintf(stderr, "Nothing specified, nothing added.\n");
		fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
		return 0;
	}
	pathspec = validate_pathspec(argc, argv, prefix);

	if (read_cache() < 0)
		die("index file corrupt");
	treat_gitlinks(pathspec);

	if (add_new_files) {
		int baselen;

		/* Set up the default git porcelain excludes */
		memset(&dir, 0, sizeof(dir));
		if (!ignored_too) {
			dir.flags |= DIR_COLLECT_IGNORED;
			setup_standard_excludes(&dir);
		}

		/* This picks up the paths that are not tracked */
		baselen = fill_directory(&dir, pathspec);
		if (pathspec)
			seen = prune_directory(&dir, pathspec, baselen);
	}

	if (refresh_only) {
		refresh(verbose, pathspec);
		goto finish;
	}

	if (pathspec) {
		int i;
		if (!seen)
			seen = find_used_pathspec(pathspec);
		for (i = 0; pathspec[i]; i++) {
			if (!seen[i] && pathspec[i][0]
			    && !file_exists(pathspec[i])) {
				if (ignore_missing) {
					if (excluded(&dir, pathspec[i], DT_UNKNOWN))
						dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
				} else
					die("pathspec '%s' did not match any files",
					    pathspec[i]);
			}
		}
		free(seen);
	}

	exit_status |= add_files_to_cache(prefix, pathspec, flags);

	if (add_new_files)
		exit_status |= add_files(&dir, flags);

 finish:
	if (active_cache_changed) {
		if (write_cache(newfd, active_cache, active_nr) ||
		    commit_locked_index(&lock_file))
			die("Unable to write new index file");
	}

	return exit_status;
}
Example #12
0
File: fb.c Project: gettler/mvpmc
static void
select_callback(mvp_widget_t *widget, char *item, void *key)
{
	char path[1024], *ptr;
	struct stat64 sb;

	sprintf(path, "%s/%s", cwd, item);
	if (stat64(path, &sb)!=0) {
		printf("Could not stat %s error %d\n",item,errno);
		if (strcmp(item,"../")==0 ) {
			// probably lost network put you back in root
			strcpy(cwd,"/");
			strcpy(path,"/");
			stat64(path, &sb);
		}
	}

	if (current_pl && !is_playlist(item)) {
		free(current_pl);
		current_pl = NULL;
	}

	if (current_pl && (playlist == NULL)) {
		free(current_pl);
		current_pl = NULL;
	}

	printf("%s(): path '%s'\n", __FUNCTION__, path);

	if (current && (strcmp(path, current) == 0)) {
		printf("selected current item\n");
		if (is_video(item) || (is_streaming(item) > 100)) {
			mvpw_hide(widget);
			mvpw_hide(fb_progress);
			av_move(0, 0, 0);
			screensaver_disable();
			return;
		}
	}

	if (current_pl && (strcmp(path, current_pl) == 0)) {
		if (is_playlist(item)) {
			mvpw_show(fb_progress);
			mvpw_set_timer(fb_progress, fb_osd_update, 500);
			mvpw_hide(widget);
			printf("Show playlist menu\n");
			mvpw_show(playlist_widget);
			mvpw_focus(playlist_widget);
			return;
		}
	}

	if (S_ISDIR(sb.st_mode)) {
		if (strcmp(item, "../") == 0) {
			strcpy(path, cwd);
			if (path[strlen(path)-1] == '/')
				path[strlen(path)-1] = '\0';
			if ((ptr=strrchr(path, '/')) != NULL)
				*ptr = '\0';
			if (path[0] == '\0')
				sprintf(path, "/");
		} else {
			if ((ptr=strrchr(path, '/')) != NULL)
				*ptr = '\0';
		}
		if (strstr(path,"/uPnP")!=NULL && strstr(cwd,"/uPnP")==NULL ){
			mount_djmount(path);
				
		} else if (strstr(path,"/uPnP")==NULL && strstr(cwd,"/uPnP")!=NULL ) { 
			unmount_djmount();
		}
		strncpy(cwd, path, sizeof(cwd));

		while ((cwd[0] == '/') && (cwd[1] == '/'))
			memmove(cwd, cwd+1, strlen(cwd));

		mvpw_clear_menu(widget);
		mvpw_set_menu_title(widget, cwd);

		busy_start();
		add_dirs(widget);
		add_files(widget);
		busy_end();

		mvpw_expose(widget);
	} else {
		switch_hw_state(MVPMC_STATE_FILEBROWSER);

		if (current)
			free(current);
		current = NULL;
		audio_stop = 1;
		pthread_kill(audio_thread, SIGURG);

		while (audio_playing)
			usleep(1000);

		current = strdup(path);

		if (is_streaming(item) > 100) {
			// Use VLC callbacks for streaming items
			video_functions = &vlc_functions;
			// Allow broadcast messages to be sent so
			// we can tell VLC to start the stream
			vlc_broadcast_enabled = 1;
		} else {
			video_functions = &file_functions;
		}

		add_osd_widget(fb_program_widget, OSD_PROGRAM,
			       osd_settings.program, NULL);

		mvpw_set_text_str(fb_name, item);

		/*
		 * This code sends the currently playing file name to the display.
		 */
		snprintf(display_message, sizeof(display_message),
			 "File:%s\n", item);
		display_send(display_message);

		audio_clear();
		video_clear();
		playlist_clear();

		if (is_video(item)) {
			if (key != NULL) {
				mvpw_hide(widget);
				mvpw_hide(fb_progress);
				av_move(0, 0, 0);
			} else {
				mvpw_show(fb_progress);
			}
			mvpw_set_timer(fb_progress, fb_osd_update, 500);
			video_play(NULL);
			mvpw_show(root);
			mvpw_expose(root);
			mvpw_focus(root);
		} else if (is_audio(item) || is_streaming(item)>=0 ) {
			mvpw_show(fb_progress);
			mvpw_set_timer(fb_progress, fb_osd_update, 500);
			audio_play(NULL);
		} else if (is_image(item)) {
			mvpw_hide(widget);
			printf("Displaying image '%s'\n", path);
			if (mvpw_load_image_jpeg(iw, path) == 0) {
				mvpw_show_image_jpeg(iw);
				av_wss_update_aspect(WSS_ASPECT_UNKNOWN);
			} else {
				mvpw_set_image(iw, path);
			}
			mvpw_show(iw);
			mvpw_focus(iw);
			loaded_offset = 0;
			loaded_status = 0;
			fb_next_image(1);
		} else if (is_playlist(item)) {
			if (current_pl)
				free(current_pl);
			current_pl = strdup(path);
			mvpw_show(fb_progress);
			mvpw_set_timer(fb_progress, fb_osd_update, 500);
			mvpw_hide(widget);
			printf("Show playlist menu\n");
			mvpw_show(playlist_widget);
			mvpw_focus(playlist_widget);
			playlist_clear();
			playlist_play(NULL);
		}
	}
}
Example #13
0
static void
read_unstaged_files_update(GitgRunner *runner, gchar **buffer, GitgCommit *commit)
{
	add_files(commit, buffer, FALSE);
}
Example #14
0
static void
read_cached_files_update(GitgRunner *runner, gchar **buffer, GitgCommit *commit)
{
	add_files(commit, buffer, TRUE);
}
Example #15
0
void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
				      int oldtype)
{
	del_files(sdata, oldtype);
	add_files(sdata);
}
Example #16
0
int recursive_dir(u8 *filedir, int filedirsz) {
    int     plen,
            namelen,
            ret     = -1;

#ifdef WIN32
    static int      winnt = -1;
    OSVERSIONINFO   osver;
    WIN32_FIND_DATA wfd;
    HANDLE          hFind = INVALID_HANDLE_VALUE;

    if(winnt < 0) {
        osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        GetVersionEx(&osver);
        if(osver.dwPlatformId >= VER_PLATFORM_WIN32_NT) {
            winnt = 1;
        } else {
            winnt = 0;
        }
    }

    plen = strlen(filedir);
    if((plen + 4) >= filedirsz) goto quit;
    strcpy(filedir + plen, "\\*.*");
    plen++;

    if(winnt) { // required to avoid problems with Vista and Windows7!
        hFind = FindFirstFileEx(filedir, FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0);
    } else {
        hFind = FindFirstFile(filedir, &wfd);
    }
    if(hFind == INVALID_HANDLE_VALUE) goto quit;
    do {
        if(!strcmp(wfd.cFileName, ".") || !strcmp(wfd.cFileName, "..")) continue;

        namelen = strlen(wfd.cFileName);
        if((plen + namelen) >= filedirsz) goto quit;
        //strcpy(filedir + plen, wfd.cFileName);
        memcpy(filedir + plen, wfd.cFileName, namelen);
        filedir[plen + namelen] = 0;

        if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
            if(recursive_dir(filedir, filedirsz) < 0) goto quit;
        } else {
            add_files(filedir, wfd.nFileSizeLow, NULL);
        }
    } while(FindNextFile(hFind, &wfd));
    ret = 0;

quit:
    if(hFind != INVALID_HANDLE_VALUE) FindClose(hFind);
#else
    struct  stat    xstat;
    struct  dirent  **namelist;
    int     n,
            i;

    n = scandir(filedir, &namelist, NULL, NULL);
    if(n < 0) {
        if(stat(filedir, &xstat) < 0) {
            fprintf(stderr, "**** %s", filedir);
            STD_ERR;
        }
        add_files(filedir, xstat.st_size, NULL);
        return(0);
    }

    plen = strlen(filedir);
    if((plen + 1) >= filedirsz) goto quit;
    strcpy(filedir + plen, "/");
    plen++;

    for(i = 0; i < n; i++) {
        if(!strcmp(namelist[i]->d_name, ".") || !strcmp(namelist[i]->d_name, "..")) continue;

        namelen = strlen(namelist[i]->d_name);
        if((plen + namelen) >= filedirsz) goto quit;
        //strcpy(filedir + plen, namelist[i]->d_name);
        memcpy(filedir + plen, namelist[i]->d_name, namelen);
        filedir[plen + namelen] = 0;

        if(stat(filedir, &xstat) < 0) {
            fprintf(stderr, "**** %s", filedir);
            STD_ERR;
        }
        if(S_ISDIR(xstat.st_mode)) {
            if(recursive_dir(filedir, filedirsz) < 0) goto quit;
        } else {
            add_files(filedir, xstat.st_size, NULL);
        }
        free(namelist[i]);
    }
    ret = 0;

quit:
    for(; i < n; i++) free(namelist[i]);
    free(namelist);
#endif
    filedir[plen - 1] = 0;
    return(ret);
}
Example #17
0
void FileSet::add_path_to_includes(const std::string& path)
{
	add_files(path, get_config().get_header_extensions());
}
Example #18
0
File: add.c Project: Noffica/git
int cmd_add(int argc, const char **argv, const char *prefix)
{
	int exit_status = 0;
	struct pathspec pathspec;
	struct dir_struct dir;
	int flags;
	int add_new_files;
	int require_pathspec;
	char *seen = NULL;
	struct lock_file lock_file = LOCK_INIT;

	git_config(add_config, NULL);

	argc = parse_options(argc, argv, prefix, builtin_add_options,
			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
	if (patch_interactive)
		add_interactive = 1;
	if (add_interactive)
		exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));

	if (edit_interactive)
		return(edit_patch(argc, argv, prefix));
	argc--;
	argv++;

	if (0 <= addremove_explicit)
		addremove = addremove_explicit;
	else if (take_worktree_changes && ADDREMOVE_DEFAULT)
		addremove = 0; /* "-u" was given but not "-A" */

	if (addremove && take_worktree_changes)
		die(_("-A and -u are mutually incompatible"));

	if (!take_worktree_changes && addremove_explicit < 0 && argc)
		/* Turn "git add pathspec..." to "git add -A pathspec..." */
		addremove = 1;

	if (!show_only && ignore_missing)
		die(_("Option --ignore-missing can only be used together with --dry-run"));

	if (chmod_arg && ((chmod_arg[0] != '-' && chmod_arg[0] != '+') ||
			  chmod_arg[1] != 'x' || chmod_arg[2]))
		die(_("--chmod param '%s' must be either -x or +x"), chmod_arg);

	add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
	require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));

	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);

	flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
		 (show_only ? ADD_CACHE_PRETEND : 0) |
		 (intent_to_add ? ADD_CACHE_INTENT : 0) |
		 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
		 (!(addremove || take_worktree_changes)
		  ? ADD_CACHE_IGNORE_REMOVAL : 0));

	if (require_pathspec && argc == 0) {
		fprintf(stderr, _("Nothing specified, nothing added.\n"));
		fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n"));
		return 0;
	}

	/*
	 * Check the "pathspec '%s' did not match any files" block
	 * below before enabling new magic.
	 */
	parse_pathspec(&pathspec, PATHSPEC_ATTR,
		       PATHSPEC_PREFER_FULL |
		       PATHSPEC_SYMLINK_LEADING_PATH,
		       prefix, argv);

	if (read_cache_preload(&pathspec) < 0)
		die(_("index file corrupt"));

	die_in_unpopulated_submodule(&the_index, prefix);
	die_path_inside_submodule(&the_index, &pathspec);

	if (add_new_files) {
		int baselen;

		/* Set up the default git porcelain excludes */
		memset(&dir, 0, sizeof(dir));
		if (!ignored_too) {
			dir.flags |= DIR_COLLECT_IGNORED;
			setup_standard_excludes(&dir);
		}

		/* This picks up the paths that are not tracked */
		baselen = fill_directory(&dir, &the_index, &pathspec);
		if (pathspec.nr)
			seen = prune_directory(&dir, &pathspec, baselen);
	}

	if (refresh_only) {
		refresh(verbose, &pathspec);
		goto finish;
	}

	if (pathspec.nr) {
		int i;

		if (!seen)
			seen = find_pathspecs_matching_against_index(&pathspec, &the_index);

		/*
		 * file_exists() assumes exact match
		 */
		GUARD_PATHSPEC(&pathspec,
			       PATHSPEC_FROMTOP |
			       PATHSPEC_LITERAL |
			       PATHSPEC_GLOB |
			       PATHSPEC_ICASE |
			       PATHSPEC_EXCLUDE);

		for (i = 0; i < pathspec.nr; i++) {
			const char *path = pathspec.items[i].match;
			if (pathspec.items[i].magic & PATHSPEC_EXCLUDE)
				continue;
			if (!seen[i] && path[0] &&
			    ((pathspec.items[i].magic &
			      (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
			     !file_exists(path))) {
				if (ignore_missing) {
					int dtype = DT_UNKNOWN;
					if (is_excluded(&dir, &the_index, path, &dtype))
						dir_add_ignored(&dir, &the_index,
								path, pathspec.items[i].len);
				} else
					die(_("pathspec '%s' did not match any files"),
					    pathspec.items[i].original);
			}
		}
		free(seen);
	}

	plug_bulk_checkin();

	if (add_renormalize)
		exit_status |= renormalize_tracked_files(&pathspec, flags);
	else
		exit_status |= add_files_to_cache(prefix, &pathspec, flags);

	if (add_new_files)
		exit_status |= add_files(&dir, flags);

	if (chmod_arg && pathspec.nr)
		chmod_pathspec(&pathspec, chmod_arg[0]);
	unplug_bulk_checkin();

finish:
	if (write_locked_index(&the_index, &lock_file,
			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
		die(_("Unable to write new index file"));

	UNLEAK(pathspec);
	UNLEAK(dir);
	return exit_status;
}
Example #19
0
void FileSet::add_path_to_link(const std::string& path)
{
	add_files(path, get_config().get_library_extensions());
}
Example #20
0
static void add_files(struct manifest *m, const char *base, const char *subdir)
{
	DIR *d;
	struct dirent *ent;
	char **subs = tal_arr(m, char *, 0);
	const char *thisdir;

	if (!subdir)
		thisdir = base;
	else
		thisdir = path_join(subs, base, subdir);

	d = opendir(thisdir);
	if (!d)
		err(1, "Opening directory %s", thisdir);

	while ((ent = readdir(d)) != NULL) {
		struct stat st;
		struct ccan_file *f;
		struct list_head *dest;
		bool is_c_src;

		if (ent->d_name[0] == '.')
			continue;

		f = new_ccan_file(m, m->dir,
				  subdir ? path_join(m, subdir, ent->d_name)
				  : ent->d_name);
		if (lstat(f->fullname, &st) != 0)
			err(1, "lstat %s", f->fullname);

		if (S_ISDIR(st.st_mode)) {
			size_t len = tal_count(subs);
			tal_resize(&subs, len+1);
			subs[len] = tal_strcat(subs, f->name, "/");
			continue;
		}
		if (!S_ISREG(st.st_mode)) {
			tal_free(f);
			continue;
		}

		if (streq(f->name, "_info")) {
			m->info_file = f;
			continue;
		}

		is_c_src = strends(f->name, ".c");
		if (!is_c_src && !strends(f->name, ".h")) {
			dest = &m->other_files;
		} else if (!strchr(f->name, '/')) {
			if (is_c_src)
				dest = &m->c_files;
			else
				dest = &m->h_files;
		} else if (strstarts(f->name, "test/")) {
			if (is_c_src) {
				if (strstarts(f->name, "test/api"))
					dest = &m->api_tests;
				else if (strstarts(f->name, "test/run"))
					dest = &m->run_tests;
				else if (strstarts(f->name, "test/compile_ok"))
					dest = &m->compile_ok_tests;
				else if (strstarts(f->name, "test/compile_fail"))
					dest = &m->compile_fail_tests;
				else
					dest = &m->other_test_c_files;
			} else
				dest = &m->other_test_files;
		} else
			dest = &m->other_files;

		list_add(dest, &f->list);
	}
	closedir(d);

	/* Before we recurse, sanity check this is a ccan module. */
	if (!subdir) {
		size_t i;

		if (!m->info_file
		    && list_empty(&m->c_files)
		    && list_empty(&m->h_files))
			errx(1, "No _info, C or H files found here!");

		for (i = 0; i < tal_count(subs); i++)
			add_files(m, base, subs[i]);
	}
	tal_free(subs);
}
Example #21
0
int main(int argc, char *argv[]) {
    files_t *files              = NULL; // scan
    int     outdirlen           = 0,
            curr_file           = 0,
            input_total_files   = 0;
    u8      filedir[PATHSZ + 1] = "",
            outdir[PATHSZ + 1]  = "",
            *p                  = NULL;

    u32     bufflen,
            filelen;
    int     i,
            forceenc    = 0,
            encver      = 1;
    u8      *filebuff,
            *buff,
            *in_file,
            *out_file;

    setbuf(stdout, NULL);
    setbuf(stderr, NULL);

    fputs("\n"
        "Race WTCC files encrypter/decrypter " VER "\n"
        "by Luigi Auriemma\n"
        "e-mail: [email protected]\n"
        "web:    aluigi.org\n"
        "\n", stdout);

#ifdef WIN32    // scan + gui
    mywnd = GetForegroundWindow();
    if(GetWindowLong(mywnd, GWL_WNDPROC)) {
        for(i = 1; i < argc; i++) {
            if(((argv[i][0] != '-') && (argv[i][0] != '/')) || (strlen(argv[i]) != 2)) {
                break;
            }
        }
        i = 2 - (argc - i);
        if(i > 0) {
            fprintf(stderr, 
                "- GUI mode activated, remember that the tool works also from command-line\n"
                "  where are available various other options and the encryption mode\n"
                "\n");
            buff = calloc(argc + i + 1, sizeof(char *));
            if(!buff) STD_ERR;
            memcpy(buff, argv, sizeof(char *) * argc);
            argv = (void *)buff;
            argc -= (2 - i);
            if(i >= 2) argv[argc + 0] = get_file("select the input file to decrypt, type \"\" for the whole folder and subfolders", 1);
            if(i >= 1) argv[argc + 1] = get_file("select the output file or folder (type \"\") where decrypting the files", 1); // multi is not used, needed for ""
            argc += 2;
        }
    }
#endif

    if(argc < 3) {
        printf("\n"
            "Usage: %s [options] <input_file/folder> <output_file/folder>\n"
            "\n"
            "Options:\n"
            "-o       overwrite output file if already exists without prompting\n"
            "-v VER   specify the file version for encryption, default %u\n"
            "-e d/e   this option is here only for compatibility reasons, it allows you\n"
            "         to force decryption 'd' or encryption 'e'\n"
            "-k GAME  select the specific key for the specific GAME which uses a non\n"
            "         default key, the following is the list of games (example -k volvo):\n"
            "           raceroom\n"
            "           volvo\n"
            "-F W     filter the input files using the W wildcard, example -F \"*.gmt\"\n"
            "-V       debug\n"
            "\n"
            "The encryption or decryption function is automatically chosen by the tool\n"
            "after having checked if the file is encrypted or not, use -e to override it.\n"
            "Note that -k volvo worked also with some old versions of RaceRoom.\n"
            "For the JCA files of RaceRoom use QuickBMS and the relative script:\n"
            "  http://quickbms.aluigi.org\n"
            "\n", argv[0], encver);
        std_err("");
    }

    argc -= 2;
    for(i = 1; i < argc; i++) {
        if(((argv[i][0] != '-') && (argv[i][0] != '/')) || (strlen(argv[i]) != 2)) {
            printf("\nError: recheck your options (%s is not valid)\n", argv[i]);
            std_err("");
        }
        switch(argv[i][1]) {
            case 'o': overwrite         = 1;                        break;
            case 'v': encver            = atoi(argv[++i]);          break;
            case 'e': forceenc          = tolower(argv[++i][0]);    break;
            case 'k': customkey         = argv[++i];                break;
            case 'F': filter_in_files   = argv[++i];                break;
            case 'V': debug             = 1;                        break;
            default: {
                printf("\nError: wrong command-line argument (%s)\n\n", argv[i]);
                std_err("");
                break;
            }
        }
    }

    if(customkey) {
        if(!stricmp(customkey, "volvo")) {
            customkey    = (u8 *)volvo_key;
            customkeylen = sizeof(volvo_key);

        } else if(!stricmp(customkey, "roomrace") || !stricmp(customkey, "raceroom")) {
            customkey    = (u8 *)raceroom_key;
            customkeylen = sizeof(raceroom_key);

        } else {
            printf("- unknown game specified with the -k option, I will consider it a hex key\n");
            customkey    = strdup(customkey);  // not needed but good
            customkeylen = string2key(customkey);
        }
    }

    in_file  = argv[argc];
    out_file = argv[argc + 1];

    // scan
#ifdef WIN32
    if(GetWindowLong(mywnd, GWL_WNDPROC) && fin[strlen(fin) + 1]) { // check if there are files after the folder
        i = snprintf(filedir, PATHSZ, "%s%c", fin, PATHSLASH);
        if((i < 0) || (i >= PATHSZ)) std_err("");
        for(p = fin;;) {
            p += strlen(p) + 1;
            if(!*p) break;
            mystrcpy(filedir + i, p, PATHSZ - i);
            add_files(filedir, 0, NULL);
        }
    } else
#endif
    if(check_is_dir(fin)) {
        printf("- start the scanning of the input folder: %s\n", fin);
        //strcpy(filedir, "."); // if you enable it you must add " + 2" to each add_files
        mystrcpy(filedir, fin, PATHSZ);
        recursive_dir(filedir, PATHSZ);
    }
    if(filedir[0]) {
        files = add_files(NULL, 0, &input_total_files);
        curr_file = 0;
        if(input_total_files <= 0) {
            printf("\nError: the input folder is empty\n");
            myexit(-2);
        }
    }
    if(check_is_dir(fout)) {
        outdirlen = snprintf(outdir, PATHSZ, "%s%c", fout, PATHSLASH);
        if((outdirlen < 0) || (outdirlen >= PATHSZ)) std_err("");
        fout = outdir;
    }

    int finlen = strlen(fin);
redo_scan:
    if(files) {
        fin = files[curr_file].name;
        curr_file++;
        fprintf(stderr, "\n");
    }
    if(outdirlen) {
        if(files) {
            for(p = fin + finlen; *p; p++) {
                if((*p != '\\') && (*p != '/')) break;
            }
        } else {
            p = strrchr(fin, '\\');
            if(!p) p = strrchr(fin, '/');
            if(p) {
                p++;
            } else {
                p = fin;
            }
        }
        mystrcpy(outdir + outdirlen, p, PATHSZ - outdirlen);
    }

redo:
    filebuff = fd_read(in_file, &filelen);

    if((memcmp(filebuff, "\x0f\xb1\xff\xff", 4) && memcmp(filebuff, "\x1f\x8b\x08", 3) && (forceenc != 'd')) || (forceenc == 'e')) {
        printf("- perform encryption:\n");
        buff = wtcc_encrypt(filebuff, filelen, &bufflen, encver);
    } else {
        printf("- perform decryption:\n");
        buff = wtcc_decrypt(filebuff, filelen, &bufflen);
    }
    if(!buff && auto_try) {
        auto_try++; // 1
        switch(auto_try) {
            case 2:
                customkey    = (u8 *)raceroom_key;
                customkeylen = sizeof(raceroom_key);
                break;
            case 3:
                customkey    = (u8 *)volvo_key;
                customkeylen = sizeof(volvo_key);
                break;
            default: auto_try = 0; break;
        }        
        free(filebuff);
        printf("\n");
        if(auto_try) goto redo;
    }

    fd_write(out_file, buff, bufflen);

    printf("- %u bytes written\n", bufflen);

    if(files && (curr_file < input_total_files)) {  // scan
        if(!((buff >= filebuff) && (buff <= (filebuff + 16)))) free(buff);
        free(filebuff);
        goto redo_scan;
    }
    fprintf(stderr, "- done\n");
    std_err("");    // scan
    return(0);
}