Example #1
0
JBoolean
JGetSVNEntryType
	(
	const JCharacter*	url,
	JString*			type,
	JString*			error
	)
{
	type->Clear();
	error->Clear();

	JString cmd = "svn info --xml " + JPrepArgForExec(url);
	JProcess* p;
	int fromFD, errFD;
	JError err = JProcess::Create(&p, cmd, kJIgnoreConnection, NULL,
								  kJCreatePipe, &fromFD, kJCreatePipe, &errFD);
	if (!err.OK())
		{
		err.ReportIfError();
		return kJFalse;
		}

	p->WaitUntilFinished();
	if (p->SuccessfulFinish())
		{
		xmlDoc* doc = xmlReadFd(fromFD, NULL, NULL, XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA);
		close(fromFD);
		if (doc != NULL)
			{
			xmlNode* root = xmlDocGetRootElement(doc);

			if (root != NULL &&
				strcmp((char*) root->name, "info") == 0 &&
				strcmp((char*) root->children->name, "entry") == 0)
				{
				*type = JGetXMLNodeAttr(root->children, "kind");
				return kJTrue;
				}
			}
		}

	JReadAll(errFD, error, kJTrue);
	return kJFalse;
}
JBoolean
JGetUserMountPointList
	(
	JMountPointList*	list,
	JMountState*		state
	)
{
	JProcess* p;
	int outFD;
	const JError err = JProcess::Create(&p, kMountCmd,
										kJIgnoreConnection, NULL,
										kJCreatePipe, &outFD,
										kJIgnoreConnection, NULL);
	if (!err.OK())
		{
		if (state != NULL)
			{
			jdelete state->mountCmdOutput;
			state->mountCmdOutput = NULL;
			}
		return kJFalse;
		}

	JString mountData;
	JReadAll(outFD, &mountData);

	p->WaitUntilFinished();
	const JBoolean success = p->SuccessfulFinish();
	jdelete p;
	p = NULL;

	if (!success)
		{
		if (state != NULL)
			{
			jdelete state->mountCmdOutput;
			state->mountCmdOutput = NULL;
			}
		return kJFalse;
		}

	if (state != NULL && state->mountCmdOutput != NULL &&
		mountData == *(state->mountCmdOutput))
		{
		return kJFalse;
		}

	list->CleanOut();
	if (state != NULL && state->mountCmdOutput == NULL)
		{
		state->mountCmdOutput = jnew JString(mountData);
		assert( state->mountCmdOutput != NULL );
		}
	else if (state != NULL)
		{
		*(state->mountCmdOutput) = mountData;
		}

	JIndexRange r;
	JArray<JIndexRange> matchList;
	JString options;
	ACE_stat stbuf;
	while (theLinePattern.MatchAfter(mountData, r, &matchList))
		{
		r = matchList.GetFirstElement();

		options = mountData.GetSubstring(matchList.GetElement(4));
		if (options.Contains("nobrowse"))
			{
			continue;
			}

		JString* path = jnew JString(mountData.GetSubstring(matchList.GetElement(3)));
		assert( path != NULL );
		JString* devicePath = jnew JString(mountData.GetSubstring(matchList.GetElement(2)));
		assert( devicePath != NULL );

		const JMountType type =
			JGetUserMountPointType(*path, *devicePath, "");
		if (type == kJUnknownMountType ||
			ACE_OS::stat(*path, &stbuf) != 0)
			{
			jdelete path;
			jdelete devicePath;
			continue;
			}

		JFileSystemType fsType = kOtherFSType;
		if (options.Contains("msdos"))
			{
			fsType = kVFATType;
			}

		list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType));
		}

	return kJTrue;
}
Example #3
0
JError
JRemoveVCS
	(
	const JCharacter*	fullName,
	const JBoolean		sync,
	JProcess**			returnP
	)
{
	if (returnP != NULL)
		{
		*returnP = NULL;
		}

	if (!JNameUsed(fullName))
		{
		return JDirEntryDoesNotExist(fullName);
		}

	JString path, name;
	JSplitPathAndName(fullName, &path, &name);

	const JString origPath = JGetCurrentDirectory();
	if (JChangeDirectory(path) != kJNoError)
		{
		return JAccessDenied(path);
		}

	JVCSType type     = JGetVCSType(path);
	JError err        = JNoError();
	JBoolean tryPlain = kJFalse;
	JString cmd;
	JProcess* p = NULL;
	if (type == kJSVNType || type == kJGitType)
		{
		const JCharacter *binary = NULL;
		if (type == kJSVNType)
			{
			binary = "svn rm --force ";
			}
		else if (type == kJGitType)
			{
			binary = "git rm -rf ";
			}

		cmd  = binary;
		cmd += JPrepArgForExec(name);
		err  = JProcess::Create(&p, cmd);
		if (err.OK())
			{
			p->WaitUntilFinished();
			}

		if (p != NULL && !p->SuccessfulFinish())
			{
			err      = JAccessDenied(fullName);
			tryPlain = kJTrue;
			}
		}
	else if (type == kJUnknownVCSType)
		{
		tryPlain = kJTrue;
		}
	else
		{
		err = JUnsupportedVCS(fullName);
		}

	if (tryPlain && JKillDirectory(fullName, sync, returnP))
		{
		err = JNoError();
		}
	else if (tryPlain)
		{
		err = JAccessDenied(fullName);
		}

	delete p;
	JChangeDirectory(origPath);
	return err;
}
Example #4
0
JError
JRenameVCS
	(
	const JCharacter* oldFullName,
	const JCharacter* newFullName
	)
{
	if (!JNameUsed(oldFullName))
		{
		return JDirEntryDoesNotExist(oldFullName);
		}

	JString oldPath, newPath, name;
	JSplitPathAndName(newFullName, &newPath, &name);
	JSplitPathAndName(oldFullName, &oldPath, &name);	// must be second

	const JString origPath = JGetCurrentDirectory();
	if (JChangeDirectory(oldPath) != kJNoError)
		{
		return JAccessDenied(oldPath);
		}

	JVCSType type1    = JGetVCSType(oldPath);
	JVCSType type2    = JGetVCSType(newPath);
	JError err        = JNoError();
	JBoolean tryPlain = kJFalse;
	JString cmd;
	JProcess* p = NULL;
	if (type1 != type2)
		{
		tryPlain = kJTrue;
		}
	else if (type1 == kJSVNType || type1 == kJGitType)
		{
		if (type1 == kJSVNType)
			{
			cmd  = "svn mv --force ";
			cmd += JPrepArgForExec(oldFullName);
			cmd += " ";
			cmd += JPrepArgForExec(newFullName);
			}
		else if (type1 == kJGitType)
			{
			cmd  = "git mv -f ";
			cmd += JPrepArgForExec(name);
			cmd += " ";
			cmd += JPrepArgForExec(newFullName);
			}

		err = JProcess::Create(&p, cmd);
		if (err.OK())
			{
			p->WaitUntilFinished();
			}

		if (p != NULL && !p->SuccessfulFinish())
			{
			err      = JAccessDenied(oldFullName, newFullName);
			tryPlain = kJTrue;
			}
		}
	else if (type1 == kJUnknownVCSType)
		{
		tryPlain = kJTrue;
		}
	else
		{
		err = JUnsupportedVCS(oldFullName);
		}

	if (tryPlain && JProgramAvailable("mv"))
		{
		cmd  = "mv ";
		cmd += JPrepArgForExec(oldFullName);
		cmd += " ";
		cmd += JPrepArgForExec(newFullName);

		JSimpleProcess* p1;
		err = JSimpleProcess::Create(&p1, cmd);
		p   = p1;
		if (err.OK())
			{
			p->WaitUntilFinished();
			if (!p->SuccessfulFinish())
				{
				err = JAccessDenied(oldFullName, newFullName);
				}
			}
		}
	else if (tryPlain)
		{
		err = JRenameDirEntry(oldFullName, newFullName);
		}

	delete p;
	JChangeDirectory(origPath);
	return err;
}