JError
JDirInfo::GoUp()
{
	JString theCWD = *itsCWD;

	// strip trailing slashes

	JStripTrailingDirSeparator(&theCWD);
	if (JIsRootDirectory(theCWD))
		{
		return JNoError();
		}

	// change directory

	JString newCWD, name;
	if (JSplitPathAndName(theCWD, &newCWD, &name))
		{
		return GoTo(newCWD);
		}
	else
		{
		return JBadPath(theCWD);
		}
}
void
JXCurrentPathMenu::SetPath
	(
	const JCharacter* path
	)
{
	RemoveAllItems();

	JString p = path;
	JCleanPath(&p);

	JString p1, n;
	while (!JIsRootDirectory(p))
		{
		JStripTrailingDirSeparator(&p);
		JSplitPathAndName(p, &p1, &n);
		PrependItem(n);
		SetItemImage(1, GetIcon(p), kJFalse);
		p = p1;
		}

	PrependItem(p);
	SetItemImage(1, GetIcon(p), kJFalse);

	const JXImage* image = NULL;
	GetItemImage(GetItemCount(), &image);
	SetTitle(GetItemText(GetItemCount()), const_cast<JXImage*>(image), kJFalse);
	SetUpdateAction(kDisableNone);
}
JMountType
JGetUserMountPointType
	(
	const JCharacter* path,
	const JCharacter* device,
	const JCharacter* fsType
	)
{
	if (strstr(fsType, "iso9660") != NULL)
		{
		return kJCDROM;
		}
	else if (strstr(fsType, "ufs") != NULL)
		{
		return kJHardDisk;
		}
	else if (strncmp("/dev/fd", device, 7) == 0)
		{
		return kJFloppyDisk;
		}
	else if (JIsRootDirectory(path))
		{
		return kJHardDisk;
		}
	else
		{
		return kJUnknownMountType;
		}
}
Beispiel #4
0
JBoolean
jSearchVCSRoot
	(
	const JCharacter*	path,
	const JCharacter*	vcsDirName,
	JString*			vcsRoot
	)
{
	JString p = path, n;
	if (JFileExists(path) ||
		!JDirectoryExists(path))	// broken link
		{
		JSplitPathAndName(path, &p, &n);
		}

	do
		{
		n = JCombinePathAndName(p, vcsDirName);
		if (JDirectoryExists(n))
			{
			*vcsRoot = p;
			return kJTrue;
			}

		JSplitPathAndName(p, &p, &n);
		}
		while (!JIsRootDirectory(p));

	vcsRoot->Clear();
	return kJFalse;
}
JMountType
JGetUserMountPointType
	(
	const JCharacter* path,
	const JCharacter* device,
	const JCharacter* fsType
	)
{
	if (strstr(fsType, "iso9660") != NULL)
		{
		return kJCDROM;
		}
	else if (strstr(path, "floppy") != NULL)
		{
		return kJFloppyDisk;	// hot-swappable drives are often /dev/sd*
		}
	else if (strncmp("/dev/hd", device, 7) == 0)		// IDE
		{
		return kJHardDisk;
		}
	else if (strncmp("/dev/sd", device, 7) == 0)		// SCSI
		{
		return kJHardDisk;
		}
	else if (strncmp("/dev/fd", device, 7) == 0)
		{
		return kJFloppyDisk;
		}
	else if (JIsRootDirectory(path))
		{
		return kJHardDisk;
		}
	else
		{
		return kJUnknownMountType;
		}
}
JBoolean
SyGApplication::OpenDirectory
	(
	const JString&	pathName,
	SyGTreeDir**	dir,
	JIndex*			row,
	const JBoolean	deiconify,
	const JBoolean	reportError,
	const JBoolean	forceNew,
	const JBoolean	clearSelection
	)
{
	if (dir != NULL)
		{
		*dir = NULL;
		}

	if (row != NULL)
		{
		*row = 0;
		}

	JString fixedName, trueName;
	if (!JExpandHomeDirShortcut(pathName, &fixedName) ||
		!JConvertToAbsolutePath(fixedName, NULL, &trueName))
		{
		if (reportError)
			{
			JString msg = "\"";
			msg += pathName;
			msg += "\" does not exist.";
			(JGetUserNotification())->ReportError(msg);
			}
		return kJFalse;
		}

	// if file, select it after opening the window

	JString selectName;
	if (JFileExists(trueName) ||
		!JDirectoryExists(trueName))	// broken link
		{
		JStripTrailingDirSeparator(&trueName);
		JString path;
		JSplitPathAndName(trueName, &path, &selectName);
		trueName = path;
		}

	// can't check this until after making sure that trueName is directory

	if (!JFSFileTreeNode::CanHaveChildren(trueName))
		{
		if (reportError)
			{
			JString msg = "Unable to read contents of \"";
			msg += pathName;
			msg += "\"";
			(JGetUserNotification())->ReportError(msg);
			}
		return kJFalse;
		}

	// resolve all .. in path

	JIndex i;
	JString p, p1;
	while (trueName.LocateSubstring("..", &i))
		{
		p = trueName.GetSubstring(1, i+1);
		if (!JGetTrueName(p, &p1))
			{
			if (reportError)
				{
				JString msg = "\"";
				msg += p;
				msg += "\" does not exist.";
				(JGetUserNotification())->ReportError(msg);
				}
			return kJFalse;
			}

		trueName.ReplaceSubstring(1, i+1, p1);
		}

	// check if window is already open

	JString ancestor = trueName, n;
	JPtrArray<JString> pathList(JPtrArrayT::kDeleteAll);
	while (!JIsRootDirectory(ancestor))
		{
		const JIndex count = itsWindowList->GetElementCount();
		for (JIndex i=1; i<=count; i++)
			{
			const JString name = (itsWindowList->NthElement(i))->GetDirectory();
			if (JSameDirEntry(name, ancestor))
				{
				SyGTreeDir* childDir = itsWindowList->NthElement(i);
				childDir->Activate();
				if (dir != NULL)
					{
					*dir = childDir;
					}

				JPoint cell;
				(childDir->GetTable())->SelectName(pathList, selectName, &cell, clearSelection);
				if (row != NULL)
					{
					*row = cell.y;
					}

				return kJTrue;
				}
			}

		if (forceNew)
			{
			break;
			}

		JStripTrailingDirSeparator(&ancestor);
		JSplitPathAndName(ancestor, &p, &n);
		ancestor = p;
		pathList.Prepend(n);
		}

	// create new window

	fixedName = trueName;
	JGetTrueName(fixedName, &trueName);

	SyGTreeDir* childDir = new SyGTreeDir(trueName);
	assert( childDir != NULL );

	childDir->Activate();

	JPoint cell;
	(childDir->GetTable())->SelectName(selectName, NULL, &cell);
	if (row != NULL)
		{
		*row = cell.y;
		}

	if (deiconify)
		{
		childDir->GetWindow()->Deiconify();
		}
	itsWindowList->Append(childDir);

	if (dir != NULL)
		{
		*dir = childDir;
		}
	return kJTrue;
}
JBoolean
JGetUserMountPointList
	(
	JMountPointList*	list,
	JMountState*		state
	)
{
	time_t t;
	if (state != NULL &&
		(!(JGetModificationTime(kAvailInfoName, &t)).OK() ||
		 t == state->modTime))
		{
		return kJFalse;
		}

	list->CleanOut();
	if (state != NULL)
		{
		state->modTime = t;
		}

	FILE* f = setmntent(kAvailInfoName, "r");
	if (f == NULL)
		{
		return kJTrue;	// did clear list
		}

	const JBoolean isRoot = JI2B( getuid() == 0 );

	ACE_stat stbuf;
	while (const mntent* info = getmntent(f))
		{
		if (!(isRoot ||
			  hasmntopt(info, "user") != NULL  ||
			  hasmntopt(info, "users") != NULL ||
			  hasmntopt(info, "pamconsole") != NULL ||
			  (jUserOwnsDevice(info->mnt_fsname) &&
			   hasmntopt(info, "owner") != NULL)) ||
			JIsRootDirectory(info->mnt_dir) ||
			strcmp(info->mnt_type, MNTTYPE_SWAP) == 0)
			{
			continue;
			}

		const JMountType type =
			JGetUserMountPointType(info->mnt_dir, info->mnt_fsname, info->mnt_type);
		if (type == kJUnknownMountType ||
			ACE_OS::stat(info->mnt_dir, &stbuf) != 0)
			{
			continue;
			}

		JFileSystemType fsType = kOtherFSType;
		if (JStringCompare(info->mnt_type, "vfat", kJFalse) == 0)
			{
			fsType = kVFATType;
			}

		JString* path = jnew JString(info->mnt_dir);
		assert( path != NULL );
		JString* devicePath = jnew JString(info->mnt_fsname);
		assert( devicePath != NULL );
		list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType));
		}

	endmntent(f);
	return kJTrue;
}
JBoolean
JGetUserMountPointList
	(
	JMountPointList*	list,
	JMountState*		state
	)
{
	time_t t;
	if (state != NULL &&
		(!(JGetModificationTime(kAvailInfoName, &t)).OK() ||
		 t == state->modTime))
		{
		return kJFalse;
		}

	list->CleanOut();
	if (state != NULL)
		{
		state->modTime = t;
		}

	FILE* f = fopen(kAvailInfoName, "r");
	if (f == NULL)
		{
		return kJTrue;	// did clear list
		}

	const JBoolean isRoot = JI2B( getuid() == 0 );

	if (isRoot)
		{
		ACE_stat stbuf;
		vfstab info;
		while (getvfsent(f, &info) == 0)
			{
			if (JIsRootDirectory(info.vfs_mountp) ||
				strcmp(info.vfs_fstype, "swap") == 0)
				{
				continue;
				}

			const JMountType type =
				JGetUserMountPointType(info.vfs_mountp, info.vfs_special, info.vfs_fstype);
			if (type == kJUnknownMountType ||
				ACE_OS::stat(info.vfs_mountp, &stbuf) != 0)
				{
				continue;
				}

			JFileSystemType fsType = kOtherFSType;
			if (JStringCompare(info.fs_vfstype, "vfat", kJFalse) == 0)
				{
				fsType = kVFATType;
				}

			JString* path = jnew JString(info.vfs_mountp);
			assert( path != NULL );
			JString* devicePath = jnew JString(info.vfs_special);
			assert( devicePath != NULL );
			list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType));
			}
		}

	fclose(f);
	return kJTrue;
}
JBoolean
JGetUserMountPointList
	(
	JMountPointList*	list,
	JMountState*		state
	)
{
	time_t t;
	if (state != NULL &&
		(!(JGetModificationTime(_PATH_FSTAB, &t)).OK() ||
		 t == state->modTime))
		{
		return kJFalse;
		}

	list->CleanOut();
	if (state != NULL)
		{
		state->modTime = t;
		}

	endfsent();

	const JBoolean isRoot = JI2B( getuid() == 0 );

	if (isRoot)
		{
		ACE_stat stbuf;
		while (const fstab* info = getfsent())
			{
			if (JIsRootDirectory(info->fs_file) ||
				strcmp(info->fs_type, FSTAB_SW) == 0)	// swap partition
				{
				continue;
				}

			const JMountType type =
				JGetUserMountPointType(info->fs_file, info->fs_spec, info->fs_vfstype);
			if (type == kJUnknownMountType ||
				ACE_OS::stat(info->fs_file, &stbuf) != 0)
				{
				continue;
				}

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

			JFileSystemType fsType = kOtherFSType;
			if (JStringCompare(info->fs_vfstype, "vfat", kJFalse) == 0)
				{
				fsType = kVFATType;
				}

			JString* path = jnew JString(info->fs_file);
			assert( path != NULL );
			JString* devicePath = jnew JString(info->fs_spec);
			assert( devicePath != NULL );
			list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType));
			}
		}

	endfsent();
	return kJTrue;
}
Beispiel #10
0
JString
JGetClosestDirectory
	(
	const JCharacter*	origDirName,
	const JBoolean		requireWrite,
	const JCharacter*	basePath
	)
{
	assert( !JStringEmpty(origDirName) );

	JString workingDir;
	if (!JStringEmpty(basePath))
		{
		workingDir = basePath;
		JAppendDirSeparator(&workingDir);
		}
	else
		{
		workingDir = JGetCurrentDirectory();
		}

	JString dirName = origDirName;
	JString homeDir;
	JSize homeLength;
	if (origDirName[0] == '~' &&
		!JExpandHomeDirShortcut(origDirName, &dirName, &homeDir, &homeLength))
		{
		return JGetRootDirectory();
		}
	else if (JIsRelativePath(origDirName))
		{
		dirName.Prepend(workingDir);
		}

	assert( !JIsRelativePath(dirName) );

	JString newDir, junkName;
	while (!JDirectoryExists(dirName)   ||
		   !JCanEnterDirectory(dirName) ||
		   !JDirectoryReadable(dirName) ||
		   (requireWrite && !JDirectoryWritable(dirName)))
		{
		JStripTrailingDirSeparator(&dirName);
		if (JIsRootDirectory(dirName))
			{
			break;
			}
		JSplitPathAndName(dirName, &newDir, &junkName);
		dirName = newDir;
		}

	// convert back to partial path, if possible

	if (origDirName[0] == '~' &&
		dirName.BeginsWith(homeDir))
		{
		dirName.ReplaceSubstring(1, homeDir.GetLength(), origDirName, homeLength);
		}
	else if (JIsRelativePath(origDirName) &&
			 dirName.GetLength() > workingDir.GetLength() &&
			 dirName.BeginsWith(workingDir))
		{
		dirName.RemoveSubstring(1, workingDir.GetLength());
		}

	return dirName;
}