Пример #1
0
Файл: dir.c Проект: bak3r-/git
static int treat_leading_path(struct dir_struct *dir,
			      const char *path, int len,
			      const struct path_simplify *simplify)
{
	struct strbuf sb = STRBUF_INIT;
	int baselen, rc = 0;
	const char *cp;
	int old_flags = dir->flags;

	while (len && path[len - 1] == '/')
		len--;
	if (!len)
		return 1;
	baselen = 0;
	dir->flags &= ~DIR_SHOW_OTHER_DIRECTORIES;
	while (1) {
		cp = path + baselen + !!baselen;
		cp = memchr(cp, '/', path + len - cp);
		if (!cp)
			baselen = len;
		else
			baselen = cp - path;
		strbuf_setlen(&sb, 0);
		strbuf_add(&sb, path, baselen);
		if (!is_directory(sb.buf))
			break;
		if (simplify_away(sb.buf, sb.len, simplify))
			break;
		if (treat_one_path(dir, &sb, simplify,
				   DT_DIR, NULL) == path_none)
			break; /* do not recurse into it */
		if (len <= baselen) {
			rc = 1;
			break; /* finished checking */
		}
	}
	strbuf_release(&sb);
	dir->flags = old_flags;
	return rc;
}
Пример #2
0
static	int	parsedirectory (const char *dir, dki_t **listp, int sub_before)
{
	dki_t	*dkp;
	DIR	*dirp;
	struct  dirent  *dentp;
	char	path[MAX_PATHSIZE+1];

	if ( dirflag )
		return 0;

	dbg_val ("directory: opendir(%s)\n", dir);
	if ( (dirp = opendir (dir)) == NULL )
		return 0;

	while ( (dentp = readdir (dirp)) != NULL )
	{
		if ( is_dotfilename (dentp->d_name) )
			continue;

		dbg_val ("directory: check %s\n", dentp->d_name);
		pathname (path, sizeof (path), dir, dentp->d_name, NULL);
		if ( is_directory (path) && recflag )
		{
			dbg_val ("directory: recursive %s\n", path);
			parsedirectory (path, listp, sub_before);
		}
		else if ( is_keyfilename (dentp->d_name) )
			if ( (dkp = dki_read (dir, dentp->d_name)) )
			{
				// fprintf (stderr, "parsedir: tssearch (%d %s)\n", dkp, dkp->name);
#if defined (USE_TREE) && USE_TREE
				dki_tadd (listp, dkp, sub_before);
#else
				dki_add (listp, dkp);
#endif
			}
	}
	closedir (dirp);
	return 1;
}
Пример #3
0
// This deletes a directory with no hidden files and subdirectories.
// Also deletes a single file.
bool delete_directory(const std::string& path, const bool keep_pbl)
{
	bool ret = true;
	std::vector<std::string> files;
	std::vector<std::string> dirs;

	get_files_in_dir(path, &files, &dirs, ENTIRE_FILE_PATH, keep_pbl ? SKIP_PBL_FILES : NO_FILTER);

	if(!files.empty()) {
		for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
			errno = 0;
			if(remove((*i).c_str()) != 0) {
				LOG_FS << "remove(" << (*i) << "): " << strerror(errno) << "\n";
				ret = false;
			}
		}
	}

	if(!dirs.empty()) {
		for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
			if(!delete_directory(*j))
				ret = false;
		}
	}

	errno = 0;
#ifdef _WIN32
	// remove() doesn't delete directories on windows.
	int (*remove)(const char*);
	if(is_directory(path))
		remove = rmdir;
	else
		remove = ::remove;
#endif
	if(remove(path.c_str()) != 0) {
		LOG_FS << "remove(" << path << "): " << strerror(errno) << "\n";
		ret = false;
	}
	return ret;
}
Пример #4
0
static bool is_binary(const char *line, const size_t len) {
  const char *ptr;

  if (is_directory(line, len)) {
    return false;
  }

  ptr = memmem(line, len, "bin/", 4);

  /* toss out the obvious non-matches */
  if (!ptr) {
    return false;
  }

  /* match bin/... */
  if (ptr == line) {
    goto found_match_candidate;
  }

  /* match sbin/... */
  if (line == ptr - 1 && ptr[-1] == 's') {
    goto found_match_candidate;
  }

  /* match .../bin/ */
  if (ptr[-1] == '/') {
    goto found_match_candidate;
  }

  /* match .../sbin/ */
  if (ptr >= line + 2 && ptr[-2] == '/' && ptr[-1] == 's') {
    goto found_match_candidate;
  }

  return false;

found_match_candidate:
  /* ensure that we only match /bin/bar and not /bin/foo/bar */
  return memchr(ptr + 4, '/', (line + len) - (ptr + 4)) == NULL;
}
Пример #5
0
static BOOL cb_walk_campaign(char* name, uint32_t flags, uint64_t len, int64_t lastWriteTime, uint32_t* ctx)
{
	char text1[_MAX_PATH], text2[_MAX_PATH];
	BOOL fok;
	walk_campaign_param_t* wcp = (walk_campaign_param_t*)ctx;

	if (flags & FILE_ATTRIBUTE_DIRECTORY ) {
		sprintf(text2, "%s\\%s", wcp->ins_campaign_dir.c_str(), name);
		MakeDirectory(std::string(text2)); // !!不要在<data>/campaigns/{campaign}下建images目录
		sprintf(text1, "%s\\%s\\images", wcp->src_campaign_dir.c_str(), name);
		sprintf(text2, "%s\\%s\\images", wcp->ins_campaign_dir.c_str(), name);
		if (is_directory(text1)) {
			posix_print("<data>, copy %s to %s ......\n", text1, text2);
			fok = copyfile(text1, text2);
			if (!fok) {
				posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
				return FALSE;
			}
		}
	}
	return TRUE;
}
bool remove_all(const path & p) {
	
	if(!exists(p)) {
		return true;
	}
	
	bool succeeded = true;
	
	if(is_directory(p)) {
		for(directory_iterator it(p); !it.end(); ++it) {
			if(it.is_regular_file()) {
				succeeded &= remove(p / it.name());
			} else {
				succeeded &= remove_all(p / it.name());
			}
		}
	}
	
	succeeded &= remove(p);
	
	return succeeded;
}
Пример #7
0
int lstat64(const char * path, struct stat64 * sb)
{
#define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
	int result=0;
	char newpath[260];
	
	*newpath=0;
	if(!is_directory(path)&&__darwintrace_is_in_sandbox(path, newpath)==0)
	{
		errno=ENOENT;
		result=-1;
	}else
	{
		if(*newpath)
			path=newpath;
			
		result=lstat64(path, sb);
	}
	
	return result;
#undef lstat64
}
Пример #8
0
static UString findSubDirectory_internal(const UString &directory, const UString &subDirectory,
		bool caseInsensitive) {

	try {
		// Special case: . is the same, current directory
		if (subDirectory == UString("."))
			return directory;

		const path dirPath(directory.c_str());

		// Special case: .. is the parent directory
		if (subDirectory == UString("..")) {
			path parent = dirPath.parent_path();
			if (parent == dirPath)
				return "";

			return parent.generic_string();
		}

		// Iterator over the directory's contents
		directory_iterator itEnd;
		for (directory_iterator itDir(dirPath); itDir != itEnd; ++itDir) {
			if (is_directory(itDir->status())) {
				// It's a directory. Check if it's the one we're looking for

				if (caseInsensitive) {
					if (iequals(itDir->path().filename().string(), subDirectory.c_str()))
						return itDir->path().generic_string();
				} else {
					if (equals(itDir->path().filename().string(), subDirectory.c_str()))
						return itDir->path().generic_string();
				}
			}
		}
	} catch (...) {
	}

	return "";
}
Пример #9
0
void CheckExternalScripts::addAllScriptsFrom(std::string str_path) {
	std::string pattern = "*.*";
	boost::filesystem::path path(str_path);
	if (!boost::filesystem::is_directory(path)) {
		if (path.has_relative_path())
			path = get_base_path() / path;
		if (!boost::filesystem::is_directory(path)) {
			file_helpers::patterns::pattern_type split_path = file_helpers::patterns::split_pattern(path);
			if (!boost::filesystem::is_directory(split_path.first)) {
				NSC_LOG_ERROR_STD("Path was not found: " + split_path.first.string());
				return;
			}
			path = split_path.first;
			pattern = split_path.second.string();
		}
	}
	NSC_DEBUG_MSG("Using script path: " + path.string());
	boost::regex re;
	try {
		std::string pre = file_helpers::patterns::glob_to_regexp(pattern);
		NSC_DEBUG_MSG("Using regexp: " + pre);
		re = pre;
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("Invalid pattern: " + pattern, e);
		return;
	}
	boost::filesystem::directory_iterator end_itr;
	for (boost::filesystem::directory_iterator itr(path); itr != end_itr; ++itr) {
		if (!is_directory(itr->status())) {
			std::string name = file_helpers::meta::get_filename(itr->path());
			std::string cmd = itr->path().string();
			if (allowArgs_) {
				cmd += " %ARGS%";
			}
			if (regex_match(name, re))
				add_command(name, cmd);
		}
	}
}
Пример #10
0
int main(int argc, char *argv[])
{
  string path;
  GuiPlanner *gui;
  Model *m = NULL;
  Geom *g = NULL;
  Problem *prob;

  if (argc < 2) {
    cout << "Usage:    plangl <problem path>\n";
    exit(-1);
  }

#ifdef WIN32
  path = string(argv[1]);
#else
  path = string(argv[1])+"/";
#endif

  if (!is_directory(path)) {
    cout << "Error:   Directory does not exist\n";
    exit(-1);
  }

#ifdef WIN32
  path = path + "/";
#endif

  SetupProblem(m,g,path);
  
  prob = new Problem(g,m,path);

  gui = new GuiPlanner(new RenderGL(new Scene(prob, path), path),
		       new RRTConCon(prob));

  gui->Start();

  return 0;
}
Пример #11
0
unsigned is_submodule_checkout_safe(const char *path, const unsigned char sha1[20])
{
	struct strbuf buf = STRBUF_INIT;
	struct child_process cp;
	const char *hex_sha1 = sha1_to_hex(sha1);
	const char *argv[] = {
		"read-tree",
		"-n",
		"-m",
		"HEAD",
		hex_sha1,
		NULL,
	};
	const char *git_dir;

	strbuf_addf(&buf, "%s/.git", path);
	git_dir = read_gitfile(buf.buf);
	if (!git_dir)
		git_dir = buf.buf;
	if (!is_directory(git_dir)) {
		strbuf_release(&buf);
		/* The submodule is not populated, it's safe to check it out */
		/*
		 * TODO: When git learns to re-populate submodules, a check must be
		 * added here to assert that no local files will be overwritten.
		 */
		return 1;
	}
	strbuf_release(&buf);

	memset(&cp, 0, sizeof(cp));
	cp.argv = argv;
	cp.env = local_repo_env;
	cp.git_cmd = 1;
	cp.no_stdin = 1;
	cp.dir = path;
	return run_command(&cp) == 0;
}
Пример #12
0
// Win32::Symlink::symlink(file, symlink)
static VALUE
rb_symlink(VALUE mod, VALUE target, VALUE symlink)
{
	(void)mod;

	VALUE error = Qnil;
	wchar_t* wtarget = NULL;
	wchar_t* wsymlink = NULL;
	BOOL res;
	DWORD flags = 0;

	target = FilePathValue(target);
	symlink = FilePathValue(symlink);
	target = rb_str_encode_ospath(target);
	symlink = rb_str_encode_ospath(symlink);

	wtarget = filecp_to_wstr(RSTRING_PTR(target), NULL);
	wsymlink = filecp_to_wstr(RSTRING_PTR(symlink), NULL);

	if( is_directory(wtarget) )
	{
		flags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
	}
	res = create_symbolic_linkW(wsymlink, wtarget, flags);
	if( !res )
	{
		error = make_api_error(RSTRING_PTR(target));
	}

	xfree(wtarget);
	xfree(wsymlink);

	if( !NIL_P(error) )
	{
		rb_exc_raise(error);
	}
	return INT2FIX(0);
}
Пример #13
0
static int add_submodule_odb(const char *path)
{
	struct strbuf objects_directory = STRBUF_INIT;
	struct alternate_object_database *alt_odb;
	int ret = 0;
	const char *git_dir;

	strbuf_addf(&objects_directory, "%s/.git", path);
	git_dir = read_gitfile(objects_directory.buf);
	if (git_dir) {
		strbuf_reset(&objects_directory);
		strbuf_addstr(&objects_directory, git_dir);
	}
	strbuf_addstr(&objects_directory, "/objects/");
	if (!is_directory(objects_directory.buf)) {
		ret = -1;
		goto done;
	}
	/* avoid adding it twice */
	for (alt_odb = alt_odb_list; alt_odb; alt_odb = alt_odb->next)
		if (alt_odb->name - alt_odb->base == objects_directory.len &&
				!strncmp(alt_odb->base, objects_directory.buf,
					objects_directory.len))
			goto done;

	alt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));
	alt_odb->next = alt_odb_list;
	strcpy(alt_odb->base, objects_directory.buf);
	alt_odb->name = alt_odb->base + objects_directory.len;
	alt_odb->name[2] = '/';
	alt_odb->name[40] = '\0';
	alt_odb->name[41] = '\0';
	alt_odb_list = alt_odb;
	prepare_alt_odb();
done:
	strbuf_release(&objects_directory);
	return ret;
}
Пример #14
0
/**
 * @internal
 */
static void update_progress_counters(winx_file_info *f,udefrag_job_parameters *jp)
{
    ULONGLONG filesize;

    jp->pi.files ++;
    if(is_directory(f)) jp->pi.directories ++;
    if(is_compressed(f)) jp->pi.compressed ++;
    jp->pi.processed_clusters += f->disp.clusters;

    filesize = f->disp.clusters * jp->v_info.bytes_per_cluster;
    if(filesize >= GIANT_FILE_SIZE)
        jp->f_counters.giant_files ++;
    else if(filesize >= HUGE_FILE_SIZE)
        jp->f_counters.huge_files ++;
    else if(filesize >= BIG_FILE_SIZE)
        jp->f_counters.big_files ++;
    else if(filesize >= AVERAGE_FILE_SIZE)
        jp->f_counters.average_files ++;
    else if(filesize >= SMALL_FILE_SIZE)
        jp->f_counters.small_files ++;
    else
        jp->f_counters.tiny_files ++;
}
Пример #15
0
int main(int ac, char** av) try
{
    if (ac < 2) {
        std::cout << "Usage: " << av[0] << " path\n";
        return 1;
    }

    fs::path p(av[1]);

    if(!exists(p) || !is_directory(p)) {
        std::cout << p << " is not a path\n";
        return 1;
    }

    fs::recursive_directory_iterator begin(p), end;
    std::vector<fs::directory_entry> v(begin, end); // vector created here

    std::cout << "There are " << v.size() << " files: \n";
    for(auto& f: v)
        std::cout << f << '\n';
} catch(std::exception& e) {
    std::cout << e.what() << '\n';
}
Пример #16
0
UString FilePath::findSubDirectory(const UString &directory, const UString &subDirectory,
		bool caseInsensitive) {

	if (!exists(directory.c_str()) || !is_directory(directory.c_str()))
		// Path is either no directory or doesn't exist
		return "";

	if (subDirectory.empty())
		// Subdirectory to look for is empty, return the directory instead
		return directory;

	// Split the subDirectory string into actual directories
	std::list<UString> dirs;
	splitDirectories(subDirectory, dirs);

	// Iterate over the directory list to find each successive subdirectory
	UString curDir = directory;
	for (std::list<UString>::iterator it = dirs.begin(); it != dirs.end(); ++it)
		if ((curDir = findSubDirectory_internal(curDir, *it, caseInsensitive)).empty())
			return "";

	return curDir;
}
Пример #17
0
/* Load CA root certificates
 */
int tls_load_ca_root_certs(char *source, mbedtls_x509_crt **ca_root_certs) {
	int result;
	char *error_msg = "Error loading root CA certificates from %s";

	if ((*ca_root_certs = (mbedtls_x509_crt*)malloc(sizeof(mbedtls_x509_crt))) == NULL) {
		return -1;
	}
	mbedtls_x509_crt_init(*ca_root_certs);

	if (is_directory(source)) {
		if ((result = mbedtls_x509_crt_parse_path(*ca_root_certs, source)) != 0) {
			print_tls_error(result, error_msg, source);
			return -1;
		}
	} else {
		if ((result = mbedtls_x509_crt_parse_file(*ca_root_certs, source)) != 0) {
			print_tls_error(result, error_msg, source);
			return -1;
		}
	}

	return 0;
}
Пример #18
0
    bool DirectoryOp::delete_directory(const char* dirname)
    {
      if (dirname == NULL)
        return false;

      bool ret = true;
      bool isexist = true;
      if (!exists(dirname))
        isexist = false;

      if (isexist)
      {
        if (!is_directory(dirname))
          ret = false;
      }

      if (ret && isexist)
      {
        if (rmdir(dirname) != 0)
          ret = false;
      }
      return !isexist ? true : ret;
    }
Пример #19
0
// Get program path from PATH variable.
static char *
get_executable_dir_from_path(char *name)
{
  if (name[0] != '/') {
    char *path = getenv("PATH");
    if (path != NULL) {
      char *p = string_copy(path);
      char *tmp;
      char *dir;
      while ((dir = strtok_r(p, ":", &tmp)) != NULL) {
	if (is_directory(dir)) {
	  char filename[MAXPATHLEN];
	  snprintf(filename, MAXPATHLEN, "%s/%s", dir, name);
	  if (is_executable(filename)) {
	    return string_copy(filename);
	  }
	}
        p = NULL;
      }
    }
  }
  return name;
}
Пример #20
0
void Globber::FindFilesInDirectoryRecursive(const path& directory, const opString& ext, set<path>& foundfiles)
{
	//does this directory exist?
	if ( !exists( directory ) )
		return;

	directory_iterator end_itr; // default construction yields past-the-end
	for ( directory_iterator itr( directory ); itr != end_itr; ++itr )
	{
		if (is_directory( *itr ) )
		{
			FindFilesInDirectoryRecursive(*itr,ext,foundfiles);
		}
		else
		{
			//get the path opstring..
			path path_found = *itr;

			//does the extension match?
			if(extension(path_found) == ext)
				foundfiles.insert(path_found);
		}
	}}
Пример #21
0
void Globber::FindFilesInDirectory(const opString& directory, const opString& extension, vector<opString>& foundfiles)
{
	path dirpath = directory.GetString();
	
	//does this directory exist?
	if ( !exists( dirpath ) )
		return;//no

	directory_iterator end_itr; // default construction yields past-the-end
	for ( directory_iterator itr( dirpath ); itr != end_itr; ++itr )
	{
		if ( !is_directory( *itr ) )
		{
			//get the path opstring..
			path path_found = *itr;
			opString filestring = path_found.string();
			
			//does the extension match?
			if(filestring.RRight(extension.Length()) == extension)
				foundfiles.push_back(filestring);
		}
	}
}
Пример #22
0
void anjuta_cvs_update (AnjutaPlugin *obj, const gchar* filename, gboolean recurse, 
	gboolean prune, gboolean create, gboolean reset_sticky, const gchar* revision, GError **err)
{
	GString* options = g_string_new("");
	CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
	gchar* command;	
	
	add_option(!recurse, options, "-l");
	add_option(prune, options, "-P");
	add_option(create, options, "-d");
	if (strlen(revision))
	{
		g_string_append_printf(options, " -r %s", revision);
	}
	else
	{
		add_option(reset_sticky, options, "-A");
	}
	
	if (!is_directory(filename))
	{
		gchar* file = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
								 NULL), "update", options->str, basename(file));
		cvs_execute(plugin, command, dirname(file));
		g_free(file);
	}
	else
	{
		gchar* dir = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
								 NULL), "update", options->str, "");
		cvs_execute(plugin, command, dir);
	}
	g_free(command);
	g_string_free(options, TRUE);
}
DirectoryImageSource::DirectoryImageSource(const string& directory) : ImageSource(directory), files(), index(-1) {
	path dirpath(directory);
	if (!exists(dirpath))
		throw runtime_error("DirectoryImageSource: Directory '" + directory + "' does not exist.");
	if (!is_directory(dirpath))
		throw runtime_error("DirectoryImageSource: '" + directory + "' is not a directory.");
	copy(directory_iterator(dirpath), directory_iterator(), back_inserter(files));
	/* TODO: Only copy valid images that opencv can handle. Those are:
		Built-in: bmp, portable image formats (pbm, pgm, ppm), Sun raster (sr, ras).
		With plugins, present by default: JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 (=Jasper)), 
										  TIFF files (tiff, tif), png.
		If specified: OpenEXR.
		Parameter for list of valid file extensions?
		Parameter for predicate (used by remove_if)?
		Parameter for single file extension?
		Unify the different image sources that work with file lists (DirectoryImageSource,
		FileImageSource, FileListImageSource, RepeatingFileImageSourcec), so the filtering
		does not have to be repeated in each of them. But not all of them need the filtering
		anyway (for example if a file list is given explicitly).

		First prototype version of file filtering by extension:
	*/
	vector<string> imageExtensions = { "bmp", "dib", "pbm", "pgm", "ppm", "sr", "ras", "jpeg", "jpg", "jpe", "jp2", "png", "tiff", "tif" };

	auto newFilesEnd = std::remove_if(files.begin(), files.end(), [&](const path& file) {
		string extension = file.extension().string();
		if (extension.size() > 0)
			extension = extension.substr(1);
		std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
		return std::none_of(imageExtensions.begin(), imageExtensions.end(), [&](const string& imageExtension) {
			return imageExtension == extension;
		});
	});
	files.erase(newFilesEnd, files.end());

	sort(files.begin(), files.end());
}
Пример #24
0
static int search_metafile(const char *repo, struct pkg_t *pkg,
                           struct archive *a, struct result_t *result,
                           struct archive_line_reader *buf) {
  while (reader_getline(buf, a) == ARCHIVE_OK) {
    const size_t len = buf->line.size;

    if (len == 0) {
      continue;
    }

    if (!config.directories && is_directory(buf->line.base, len)) {
      continue;
    }

    if (config.binaries && !is_binary(buf->line.base, len)) {
      continue;
    }

    if (config.filterfunc(&config.filter, buf->line.base, (int)len,
                          config.icase) == 0) {
      _cleanup_free_ char *line = NULL;
      int prefixlen = format_search_result(&line, repo, pkg);
      if (prefixlen < 0) {
        fputs("error: failed to allocate memory for result\n", stderr);
        return -1;
      }
      result_add(result, line, config.verbose ? buf->line.base : NULL,
                 config.verbose ? prefixlen : 0);

      if (!config.verbose) {
        return 0;
      }
    }
  }

  return 0;
}
Пример #25
0
void anjuta_cvs_commit (AnjutaPlugin *obj, const gchar* filename, const gchar* log,
	const gchar* rev, gboolean recurse, GError **err)
{
	GString* options = g_string_new("");
	CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
	gchar* command;	
	
	if (strlen(log))
		g_string_printf(options, "-m '%s'", log);
	else
		g_string_printf(options, "-m 'no log message'");
	
	if (strlen(rev))
	{
		g_string_append_printf(options, " -r %s", rev);
	}
	add_option(!recurse, options, "-l");
	
	if (!is_directory(filename))
	{
		gchar* file = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
			NULL), "commit", options->str, basename(file));
		cvs_execute(plugin, command, dirname(file));
		g_free(file);
	}
	else
	{
		gchar* dir = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
			NULL), "commit", options->str, "");
		cvs_execute(plugin, command, dir);
		g_free(dir);
	}
	g_free(command);
	g_string_free(options, TRUE);
}
Пример #26
0
void TransportCurl::recv(std::string target)
{
  if (uri.host == "")
    throw std::string ("when using the 'curl' protocol, the uri must contain a hostname.");

  if (uri.user != "")
  {
    arguments.push_back("--user");
    arguments.push_back(uri.user);
  }


  if (is_filelist(uri.path))
  {
    std::string::size_type pos;
    pos = uri.path.find("{");

    if (pos == std::string::npos)
      throw std::string ("When using the 'curl' protocol, wildcards are not supported.");

    if (!is_directory(target))
      throw std::string ("The uri '") + target + "' does not appear to be a directory.";

    std::string toSplit;
    std::string suffix;
    std::string prefix = target;
    std::vector<std::string> splitted;
    toSplit = uri.path.substr (pos+1);
    pos = toSplit.find ("}");
    suffix = toSplit.substr (pos+1);
    split (splitted, toSplit.substr(0, pos), ',');

    target = "";
    foreach (file, splitted)
    {
      target += " -o " + prefix + *file + suffix;
    }
Пример #27
0
static int msfs_rm (file_entry_t * entry, int recursive) {
	if(entry == NULL) return -ENOENT;
	if(msfs_error != 0) return msfs_error;

	inode_t inode = read_inode(entry->address);

	addr_t cur_addr = 0;
	int ret;

	if(recursive && is_directory(&inode)) {
		file_entry_t * file_entry;
		for(file_entry = next_file_entry(&inode, &cur_addr); file_entry != NULL; file_entry = next_file_entry(&inode, &cur_addr)) {
			if(strcmp(file_entry->name, ".") != 0 && strcmp(file_entry->name, "..") != 0) {
				ret = msfs_rm(file_entry, 1);
				if(ret != 0) return ret;
			}
			free_file_entry(file_entry);
		}
	}

	delete_file_entry(entry);
	free_file_entry(entry);
	return msfs_error;
}
Пример #28
0
std::size_t add(
         Catalog& cat,
         boost::filesystem::path const& path,
         const bool recurse,
         const std::size_t search_depth
         ) {
   if( ! exists(path) ) BOOST_THROW_EXCEPTION(
            Input_err()
            << Input_err::msg_t("not found")
            << Input_err::str1_t(path.string())
   );
   if( is_directory(path) ) {
      if( recurse ) {
         boost::filesystem::recursive_directory_iterator i1(path), i2;
         return add_to_catalog(i1, i2, cat, search_depth);
      } else {
         boost::filesystem::directory_iterator i1(path), i2;
         return add_to_catalog(i1, i2, cat, search_depth);
      }
   } else if( is_regular_file(path) ) {
      return add_to_catalog(path, cat, search_depth, false);
   }
   return 0;
}
Пример #29
0
void PathHandler::isRegularFile() const {
  if (exists(path_)) {
    if (!is_regular_file(path_)) {
      if (is_directory(path_)) {
        throw InvalidType(std::string("Error in ") +
          "\"PathHandler::isRegularFile\":\n  " +
          path_.generic_string() +
          "\n  is a directory, not a file.");
      }
      else {
        throw InvalidType(std::string("Error in ") +
          "\"PathHandler::isRegularFile\":\n  " +
          path_.generic_string() +
          "\n  exists but it is neither a regular file nor a directory.");
      }
    }
  }
  else {
    throw NonExistent(std::string("Error in ") +
      "\"PathHandler::isRegularFile\":\n  " +
      path_.generic_string() +
      "\n  does not exist.");
  }
}
Пример #30
0
    //return the size of filename
    int64_t DirectoryOp::get_size(const char *filename)
    {
      if (filename == NULL)
        return 0;

      int64_t ret = 0;
      bool is_exists = true;
      if (!exists(filename))
        is_exists = false;

      if (is_exists)
      {
        if (is_directory(filename))
          is_exists = false;
      }

      if (is_exists)
      {
        struct stat64 file_info;
        if (stat64(filename, &file_info) == 0)
          ret = file_info.st_size;
      }
      return ret;
    }