Exemple #1
0
static int incexc_munge(struct conf **c, struct strlist *s)
{
#ifdef HAVE_WIN32
	convert_backslashes(&s->path);
#endif
	if(path_checks(s->path,
		"ERROR: Please use absolute include/exclude paths.\n"))
			return -1;
	if(add_to_strlist(c[OPT_INCEXCDIR], s->path, s->flag))
		return -1;
	return 0;
}
Exemple #2
0
// This decides which directories to start backing up, and which
// are subdirectories which don't need to be started separately.
static int finalise_start_dirs(struct conf **c)
{
	struct strlist *s=NULL;
	struct strlist *last_ie=NULL;
	struct strlist *last_sd=NULL;

	// Make sure that the startdir list starts empty, or chaos will ensue.
	conf_free_content(c[OPT_STARTDIR]);

	for(s=get_strlist(c[OPT_INCLUDE]); s; s=s->next)
	{
#ifdef HAVE_WIN32
		convert_backslashes(&s->path);
#endif
		if(path_checks(s->path,
			"ERROR: Please use absolute include/exclude paths.\n"))
				return -1;

		// Ensure that we do not backup the same directory twice.
		if(last_ie && !strcmp(s->path, last_ie->path))
		{
			logp("Directory appears twice in conf: %s\n",
				s->path);
			return -1;
		}
		// If it is not a subdirectory of the most recent start point,
		// we have found another start point.
		if(!get_strlist(c[OPT_STARTDIR])
		  || !last_sd || !is_subdir(last_sd->path, s->path))
		{
			// Do not use strlist_add_sorted, because last_sd is
			// relying on incexcdir already being sorted.
			if(add_to_strlist(c[OPT_STARTDIR], s->path, s->flag))
				return -1;
			last_sd=s;
		}
		else
		{
			// If it is not a starting directory, it should at
			// least be included as a cross_filesystem entry.
			if(add_to_cross_filesystem(c, s->path))
				return -1;
		}
		last_ie=s;
	}
	return 0;
}
Exemple #3
0
static int process_entry(struct strlist *ig, struct conf **confs)
{
	int ret=-1;
	size_t len1=0;
	char *sav=NULL;
	char **splitstr1=NULL;
        WIN32_FIND_DATA ffd;
        HANDLE hFind=INVALID_HANDLE_VALUE;

	convert_backslashes(&ig->path);
	if(ig->path[strlen(ig->path)-1]!='*')
	{
		if(!(splitstr1=xstrsplit(ig->path, "*", &len1)))
			goto end;
	}
	if(len1>2)
	{
		logp("include_glob error: '%s' contains at least"
			" two '*' which is not currently supported\n",
				ig->path);
		goto end;
	}
	if(len1>1)
	{
		char *tmppath=NULL;
		if(astrcat(&tmppath, splitstr1[0], __func__)
		  || !(sav=strdup_w(tmppath, __func__))
		  || astrcat(&tmppath, "*", __func__))
			goto end;
		hFind=FindFirstFileA(tmppath, &ffd);
		free_w(&tmppath);
	}
	else
		hFind=FindFirstFileA(ig->path, &ffd);

	if(hFind==INVALID_HANDLE_VALUE)
	{
		LPVOID lpMsgBuf;
		DWORD dw=GetLastError(); 
		FormatMessage(
			FORMAT_MESSAGE_ALLOCATE_BUFFER | 
			FORMAT_MESSAGE_FROM_SYSTEM |
			FORMAT_MESSAGE_IGNORE_INSERTS,
			NULL,
			dw,
			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
			(LPTSTR)&lpMsgBuf,
			0, NULL );
		logp("Error: %s\n", lpMsgBuf);
		LocalFree(lpMsgBuf);
		goto end;
	}

	do
	{
		if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
		   && strcmp(ffd.cFileName, ".")
		   && strcmp(ffd.cFileName, ".."))
		{
			char *tmppath=NULL;
			if(len1<2)
			{
				if(ig->path[strlen(ig->path)-1]=='*')
				{
					if(!(tmppath=xstrsub(ig->path, 0,
						strlen(ig->path)-1))
					  || astrcat(&tmppath,
						ffd.cFileName, __func__))
							goto end;
				}
				else
					if(!(tmppath=strdup_w(ig->path,
						__func__))) goto end;
			}
			else
			{
				if(astrcat(&tmppath, sav, __func__)
				  || astrcat(&tmppath, ffd.cFileName, __func__)
				  || astrcat(&tmppath, splitstr1[1], __func__))
					goto end;
			}
			if(add_to_strlist(confs[OPT_INCLUDE], tmppath, 1))
				goto end;
			free_w(&tmppath);
		}
	}
	while(FindNextFileA(hFind, &ffd)!=0);

	FindClose(hFind);
	ret=0;
end:
	if(splitstr1)
	{
		free_w(&sav);
		xfree_list(splitstr1, len1);
	}
	return ret;
}