Beispiel #1
0
static int recover_currenttmp(struct sdirs *sdirs)
{
	struct stat statp;
	logp("Found currenttmp symlink\n");
	if(stat(sdirs->currenttmp, &statp))
	{
		logp("But currenttmp is not pointing at something valid.\n");
		logp("Deleting it.\n");
		return unlink_w(sdirs->currenttmp, __func__);
	}

	if(!lstat(sdirs->current, &statp))
	{
		if(S_ISLNK(statp.st_mode))
		{
			logp("But current symlink already exists!\n");
			if(!stat(sdirs->current, &statp))
			{
				logp("And current symlink points at something valid.\n");
				logp("Deleting currenttmp.\n");
				return unlink_w(sdirs->currenttmp, __func__);
				
			}
			else
			{
				logp("But current symlink is not pointing at something valid.\n");
				logp("Replacing current with currenttmp.\n");
				return do_rename(sdirs->currenttmp,
					sdirs->current);
			}
		}
		else
		{
			logp("But current already exists and is not a symlink!\n");
			logp("Giving up.\n");
			return -1;
		}
	}
	else
	{
		logp("Renaming currenttmp to current\n");
		return do_rename(sdirs->currenttmp, sdirs->current);
	}
	return 0;
}
Beispiel #2
0
static int recover_currenttmp(struct sdirs *sdirs)
{
	logp("Found currenttmp symlink\n");
	switch(is_lnk_valid(sdirs->currenttmp))
	{
		case 0:
			logp("But currenttmp is not pointing at something valid.\n");
			logp("Deleting it.\n");
			return unlink_w(sdirs->currenttmp, __func__);
		case -1:
			return -1;
	}

	switch(is_lnk(sdirs->current))
	{
		case 0:
			logp("But current already exists and is not a symlink!\n");
			logp("Giving up.\n");
			return -1;
		case 1:
			logp("But current symlink already exists!\n");
			switch(is_lnk_valid(sdirs->current))
			{
				case 0:
					logp("But current symlink is not pointing at something valid.\n");
					logp("Replacing current with currenttmp.\n");
					return do_rename(sdirs->currenttmp,
						sdirs->current);
				case 1:
					logp("And current symlink points at something valid.\n");
					logp("Deleting currenttmp.\n");
					return unlink_w(sdirs->currenttmp, __func__);
				default:
					return -1;
			}
		default:
			logp("Renaming currenttmp to current\n");
			return do_rename(sdirs->currenttmp, sdirs->current);
	}
}