コード例 #1
0
ファイル: bamFile.c プロジェクト: avilella/methylQA
static char *getSamDir()
/* Return the name of a trash dir for samtools to run in (it creates files in current dir)
 * and make sure the directory exists. */
{
    static char *samDir = NULL;
    char *dirName = "samtools";
    if (samDir == NULL)
    {
        mkdirTrashDirectory(dirName);
        size_t len = strlen(trashDir()) + 1 + strlen(dirName) + 1;
        samDir = needMem(len);
        safef(samDir, len, "%s/%s", trashDir(), dirName);
    }
    return samDir;
}
コード例 #2
0
ファイル: trash.cpp プロジェクト: mmanley/Antares
status_t foreach_in_trash(status_t (*iterator)(const char *))
{
	status_t err;
	dev_t dev;
	char trash_dir[B_PATH_NAME_LENGTH];
	for (dev = 0; ; ) {
		if (next_dev(&dev) < B_OK)
			break;
		//for each in trash_dir
		err = find_directory(B_TRASH_DIRECTORY, dev, false, trash_dir, B_PATH_NAME_LENGTH);
		if (err)
			continue; /* skip trashless volumes */
		BDirectory trashDir(trash_dir);
		err = trashDir.InitCheck();
		if (err < 0)
			return err;
		entry_ref er;
		while (trashDir.GetNextRef(&er) == B_OK) {
			BPath path(&er);
			if ((err = path.InitCheck()))
				return err;
			err = iterator(path.Path());
			if (err)
				return err;
		}
	}
	return B_OK;
}
コード例 #3
0
ファイル: trash.cpp プロジェクト: looncraz/haiku
status_t trash(const char *f)
{
	status_t err;
	attr_info ai;
	dev_t dev = -1;
	int nr;
	const char *original_path;
	char trash_dir[B_PATH_NAME_LENGTH];
	char trashed_file[B_PATH_NAME_LENGTH];
	dev = dev_for_path(f);
	err = find_directory(B_TRASH_DIRECTORY, dev, false, trash_dir, B_PATH_NAME_LENGTH);
	if (err < 0)
		return err;
	BNode node(f);
	err = node.InitCheck();
	if (err < 0)
		return err;
	err = node.GetAttrInfo(kAttrOriginalPath, &ai);
	if (err == B_OK)
		return EALREADY;
	if (!strncmp(f, trash_dir, strlen(trash_dir)))
		return EALREADY;
	entry_ref er;
	err = get_ref_for_path(f, &er);
	if (err < 0)
		return err;
	BPath orgPath(&er);
	err = orgPath.InitCheck();
	if (err < 0)
		return err;
	original_path = orgPath.Path();
	BDirectory trashDir(trash_dir);
	err = trashDir.InitCheck();
	if (err < 0)
		return err;
	for (nr = 0; ; nr++) {
		if (nr > INT_MAX - 1)
			return B_ERROR;
		if (nr)
			snprintf(trashed_file, B_PATH_NAME_LENGTH-1, "%s/%s %d", trash_dir, er.name, nr);
		else
			snprintf(trashed_file, B_PATH_NAME_LENGTH-1, "%s/%s", trash_dir, er.name);
		if (!trashDir.Contains(trashed_file))
			break;
	}
	err = rename(original_path, trashed_file);
	if (err < 0)
		return err;
	
	err = node.WriteAttr(kAttrOriginalPath, B_STRING_TYPE, 0LL, original_path, strlen(original_path)+1);
	if (err < 0)
		return err;
	return 0;
}
コード例 #4
0
ファイル: portimpl.c プロジェクト: ucscGenomeBrowser/kent
void mkdirTrashDirectory(char *prefix)
/*	create the specified trash directory if it doesn't exist */
{
struct stat buf;
char trashDirName[128];
safef(trashDirName, sizeof(trashDirName), "%s/%s", trashDir(), prefix);
if (stat(trashDirName,&buf))
    {
    int result = mkdir (trashDirName, S_IRWXU | S_IRWXG | S_IRWXO);
    if (0 != result)
	errnoAbort("failed to create directory %s", trashDirName);
    }
}
コード例 #5
0
ファイル: ThemeManager.cpp プロジェクト: mmanley/Antares
status_t
ThemeManager::DeleteTheme(int32 id)
{
	status_t err;
	BMessage *theme;
	BString loc;
	if ((id < 0) || (id >= fThemeList.CountItems()))
		return EINVAL;
	theme = (BMessage *)fThemeList.RemoveItem(id);
	fThemeList.AddItem(NULL, id); /* keep the place occupied */
	if (!theme)
		return -1;
	
	err = theme->FindString(Z_THEME_LOCATION, &loc);
	if (!err) {
		// move the files to trash...
		BEntry ent(loc.String());
		if (ent.InitCheck() == B_OK) {
			BPath trash;
			err = find_directory(B_TRASH_DIRECTORY, &trash);
			if (!err) {
				BDirectory trashDir(trash.Path());
				if (trashDir.InitCheck() == B_OK) {
					BNode nod(&ent);
					if (nod.InitCheck() == B_OK) {
						BPath path;
						err = ent.GetPath(&path);
						if (!err) {
							nod.WriteAttr("_trk/original_path", B_STRING_TYPE, 0LL, path.Path(), strlen(path.Path())+1);
						}
					}
					err = ent.MoveTo(&trashDir, NULL);  // don't clober
					if (err) {
						BString newname("Theme-renamed-");
						newname << system_time();
						err = ent.MoveTo(&trashDir, newname.String(), true);
					}
				}
			}
		}
	}
	
	if (id == fSelectedTheme)
		fSelectedTheme = -1;
	delete theme;
	return B_OK;
}
コード例 #6
0
ファイル: dtrash.cpp プロジェクト: birkedal/digikam
bool DTrash::prepareCollectionTrash(const QString& collectionPath)
{
    QString trashFolder = collectionPath + QLatin1Char('/') + TRASH_FOLDER;
    QDir trashDir(trashFolder);

    if (!trashDir.exists())
    {
        bool isCreated = true;

        isCreated &= trashDir.mkpath(trashFolder);
        isCreated &= trashDir.mkpath(trashFolder + QLatin1Char('/') + FILES_FOLDER);
        isCreated &= trashDir.mkpath(trashFolder + QLatin1Char('/') + INFO_FOLDER);

        if(!isCreated)
        {
            qCDebug(DIGIKAM_IOJOB_LOG) << "DTrash: could not create trash folder for collection";
            return false;
        }
    }

    qCDebug(DIGIKAM_IOJOB_LOG) << "Trash folder for collection: " << trashFolder;

    return true;
}
コード例 #7
0
ファイル: web.c プロジェクト: elmargb/kentUtils
static void phoneHome()
{
static boolean beenHere = FALSE;
if (beenHere)  /* one at a time please */
    return;
beenHere = TRUE;

char *expireTime = cfgOptionDefault("browser.cgiExpireMinutes", "20");
unsigned expireMinutes = sqlUnsigned(expireTime);
expireSeconds = expireMinutes * 60;

char trashFile[PATH_LEN];
safef(trashFile, sizeof(trashFile), "%s/registration.txt", trashDir());

/* trashFile does not exist during command line execution */
if(fileExists(trashFile))	/* update access time for trashFile */
    {
    struct utimbuf ut;
    struct stat mystat;
    ZeroVar(&mystat);
    if (stat(trashFile,&mystat)==0)
	{
	ut.actime = clock1();
	ut.modtime = mystat.st_mtime;
	}
    else
	{
	ut.actime = ut.modtime = clock1();
	}
    (void) utime(trashFile, &ut);
    if (expireSeconds > 0)
	{
	(void) signal(SIGALRM, cgiApoptosis);
	(void) alarm(expireSeconds);	/* CGI timeout */
	}
    return;
    }

char *scriptName = cgiScriptName();
char *ip = getenv("SERVER_ADDR");
if (scriptName && ip)  /* will not be true from command line execution */
    {
    FILE *f = fopen(trashFile, "w");
    if (f)		/* rigamarole only if we can get a trash file */
	{
	time_t now = time(NULL);
	char *localTime;
	extern char *tzname[2];
	struct tm *tm = localtime(&now);
	localTime = sqlUnixTimeToDate(&now,FALSE); /* FALSE == localtime */
	fprintf(f, "%s, %s, %s %s, %s\n", scriptName, ip, localTime,
	    tm->tm_isdst ? tzname[1] : tzname[0], trashFile);
	fclose(f);
	chmod(trashFile, 0666);
	pid_t pid0 = fork();
	if (0 == pid0)	/* in child */
	    {
	    close(STDOUT_FILENO); /* do not hang up Apache finish for parent */
	    expireSeconds = 0;	/* no error message from this exit */
	    (void) signal(SIGALRM, cgiApoptosis);
	    (void) alarm(6);	/* timeout here in 6 seconds */
#include "versionInfo.h"
	    char url[1024];
	    safef(url, sizeof(url), "%s%s%s%s%s%s", "http://",
	"genomewiki.", "ucsc.edu/", "cgi-bin/useCount?", "version=browser.v",
		CGI_VERSION);

	    /* 6 second alarm will exit this page fetch if it does not work */
	    (void) htmlPageGetWithCookies(url, NULL); /* ignore return */

	    exit(0);
	    }	/* child of fork has done exit(0) normally or via alarm */
	}		/* trash file open OK */
    if (expireSeconds > 0)
	{
	(void) signal(SIGALRM, cgiApoptosis);
	(void) alarm(expireSeconds);	/* CGI timeout */
	}
    }			/* an actual CGI binary */
}			/* phoneHome()	*/
コード例 #8
0
ファイル: FilePlaylistItem.cpp プロジェクト: AmirAbrams/haiku
status_t
FilePlaylistItem::_MoveIntoTrash(vector<entry_ref>* refs,
	vector<BString>* namesInTrash)
{
	char trashPath[B_PATH_NAME_LENGTH];
	status_t err = find_directory(B_TRASH_DIRECTORY, (*refs)[0].device,
		true /*create it*/, trashPath, B_PATH_NAME_LENGTH);
	if (err != B_OK) {
		fprintf(stderr, "failed to find Trash: %s\n", strerror(err));
		return err;
	}

	BDirectory trashDir(trashPath);
	err = trashDir.InitCheck();
	if (err != B_OK) {
		fprintf(stderr, "failed to init BDirectory for %s: %s\n",
			trashPath, strerror(err));
		return err;
	}

	for (vector<entry_ref>::size_type i = 0; i < refs->size(); i++) {
		BEntry entry(&(*refs)[i]);
		err = entry.InitCheck();
		if (err != B_OK) {
			fprintf(stderr, "failed to init BEntry for %s: %s\n",
				(*refs)[i].name, strerror(err));
			return err;
		}
	
		// Find a unique name for the entry in the trash
		(*namesInTrash)[i] = (*refs)[i].name;
		int32 uniqueNameIndex = 1;
		while (true) {
			BEntry test(&trashDir, (*namesInTrash)[i].String());
			if (!test.Exists())
				break;
			(*namesInTrash)[i] = (*refs)[i].name;
			(*namesInTrash)[i] << ' ' << uniqueNameIndex;
			uniqueNameIndex++;
		}
	
		// Remember the original path
		BPath originalPath;
		entry.GetPath(&originalPath);
	
		// Finally, move the entry into the trash
		err = entry.MoveTo(&trashDir, (*namesInTrash)[i].String());
		if (err != B_OK) {
			fprintf(stderr, "failed to move entry into trash %s: %s\n",
				trashPath, strerror(err));
			return err;
		}
	
		// Allow Tracker to restore this entry
		BNode node(&entry);
		BString originalPathString(originalPath.Path());
		node.WriteAttrString("_trk/original_path", &originalPathString);
	}

	return B_OK;
}
コード例 #9
0
ファイル: FilePlaylistItem.cpp プロジェクト: mariuz/haiku
status_t
FilePlaylistItem::MoveIntoTrash()
{
	if (fNameInTrash.Length() != 0) {
		// Already in the trash!
		return B_ERROR;
	}

	char trashPath[B_PATH_NAME_LENGTH];
	status_t err = find_directory(B_TRASH_DIRECTORY, fRef.device,
		true /*create it*/, trashPath, B_PATH_NAME_LENGTH);
	if (err != B_OK) {
		fprintf(stderr, "failed to find Trash: %s\n", strerror(err));
		return err;
	}

	BEntry entry(&fRef);
	err = entry.InitCheck();
	if (err != B_OK) {
		fprintf(stderr, "failed to init BEntry for %s: %s\n",
			fRef.name, strerror(err));
		return err;
	}
	BDirectory trashDir(trashPath);
	if (err != B_OK) {
		fprintf(stderr, "failed to init BDirectory for %s: %s\n",
			trashPath, strerror(err));
		return err;
	}

	// Find a unique name for the entry in the trash
	fNameInTrash = fRef.name;
	int32 uniqueNameIndex = 1;
	while (true) {
		BEntry test(&trashDir, fNameInTrash.String());
		if (!test.Exists())
			break;
		fNameInTrash = fRef.name;
		fNameInTrash << ' ' << uniqueNameIndex;
		uniqueNameIndex++;
	}

	// Remember the original path
	BPath originalPath;
	entry.GetPath(&originalPath);

	// Finally, move the entry into the trash
	err = entry.MoveTo(&trashDir, fNameInTrash.String());
	if (err != B_OK) {
		fprintf(stderr, "failed to move entry into trash %s: %s\n",
			trashPath, strerror(err));
		return err;
	}

	// Allow Tracker to restore this entry
	BNode node(&entry);
	BString originalPathString(originalPath.Path());
	node.WriteAttrString("_trk/original_path", &originalPathString);

	return err;
}