void EntryModel::entryRow(const QModelIndex &current, const QModelIndex &previous)
{
    Q_UNUSED(previous);
    if(current.isValid()){
        emit entryPath(&entryList[current.row()].paths);
    }else{
//        QVector<Point> * entryPaths = NULL;
        emit entryPath(NULL);
    }
}
Пример #2
0
util::Error RemoveDirectory(const acl::User& user, const VirtualPath& path)
{
  util::Error e(PP::DirAllowed<PP::Delete>(user, path));
  if (!e) return e;
  
  try
  {
    util::path::DirContainer dirCont(MakeReal(path).ToString());
    for (auto& name : dirCont)
    {
      if (name[0] !=  '.') return util::Error::Failure(ENOTEMPTY);
        
      util::path::Status status((MakeReal(path) / name).ToString());
      if (status.IsDirectory() || !status.IsWriteable())
        return util::Error::Failure(ENOTEMPTY);
    }
    
    
    for (auto& name : dirCont)
    {
      RealPath entryPath(MakeReal(path) / name);
      if (unlink(entryPath.CString()) < 0)
        return util::Error::Failure(errno);
    }
  }
  catch (const util::SystemError& e)
  {
    return util::Error::Failure(e.Errno());
  }
    
  return RemoveDirectory(MakeReal(path));
}
Пример #3
0
void DirectoryDialog::updateTable()
{
	QMutexLocker locker(&(m_directoryMgr->m_lock));

	while (m_table->rowCount() > 0)
		m_table->removeRow(0);								// clear table

	if (m_currentDirIndex == -1)
		return;												// nothing else to do

	DM_CONNECTEDCOMPONENT *connectedComponent = m_directoryMgr->m_directory + m_currentDirIndex;
	if (!connectedComponent->valid)
		return;												// not a valid entry
	DM_COMPONENT *component = connectedComponent->componentDE;

	while (component != NULL) {
		if (entryPath(component) == m_currentItem->text(0)) {			// found the correct component
			DM_SERVICE *service = component->services;
			for (int serviceIndex = 0; serviceIndex < component->serviceCount; serviceIndex++, service++) {
				if (!service->valid)
					continue;		// can this happen?
				if (service->serviceType != SERVICETYPE_NOSERVICE) {
					addTableRow(service);
				}
			}
		}
		component = component->next;
	}
}
void EntryModel::sort()
{
    beginResetModel();
    entryList.sort();
    emit entryPath(NULL);
    endResetModel();
}
void EntryModel::reset()
{
    beginResetModel();
    entryList.clear();
    emit entryPath(NULL);
    endResetModel();
}
Пример #6
0
void CHMODCommand::Process(fs::VirtualPath pathmask)
{
  auto flags = fs::GlobIterator::NoFlags;
  if (recursive) flags |= fs::GlobIterator::Recursive;

  try
  {
    for (auto& entry : fs::GlobContainer(client.User(), pathmask, flags))
    {
      fs::VirtualPath entryPath(pathmask.Dirname() / entry);
      try
      {
        util::path::Status status(fs::MakeReal(entryPath).ToString());
        util::Error e = fs::Chmod(client.User(), entryPath, *mode);
        if (!e)
        {
          ++failed;
          control.PartReply(ftp::CommandOkay, "CHOWN " +
              entryPath.ToString() + ": " + e.Message());
        }
        else
        if (status.IsDirectory()) ++dirs;
        else ++files;
      }
      catch (const util::SystemError& e)
      {
        ++failed;
        control.PartReply(ftp::CommandOkay, "CHOWN " +
            entryPath.ToString() + ": " + e.Message());
      }
    }
  }
  catch (const util::SystemError& e)
  {
    ++failed;
    control.PartReply(ftp::CommandOkay,
        "CHMOD " + pathmask.Dirname().ToString() + ": " + e.Message());
  }
}
Пример #7
0
std::vector<std::shared_ptr<Tial::Utility::_DirectoryEntry<
	Tial::Utility::NativePath
>>> Tial::Utility::_directoryContent(const NativePath &path) {
#if (BOOST_OS_UNIX || BOOST_OS_MACOS)
	std::vector<std::shared_ptr<_DirectoryEntry<NativePath>>> output;

	std::unique_ptr<DIR, std::function<void(DIR*)>> directory(
		opendir(std::string(path).c_str()),
		[](DIR *ptr) {
			closedir(ptr);
		}
	);
	if(!directory)
		throw std::system_error(errno, std::system_category());

	struct dirent *entry;
	while((entry = readdir(directory.get()))) {
		std::string name(entry->d_name);
		if(name == "." || name == "..")
			continue;

		NativePath entryPath(name);

		std::shared_ptr<_DirectoryEntry<NativePath>> outputEntry;
		if(entry->d_type == DT_DIR)
			outputEntry.reset(new Directory<NativePath>(entryPath));
		else
			outputEntry.reset(new _DirectoryEntry<NativePath>(entryPath));
		output.push_back(outputEntry);
	}

	std::sort(output.begin(), output.end());

	return output;
#else
#error "Platform not supported"
#endif
}
Пример #8
0
/*!	\brief Returns whether this directory or any of its subdirectories
	at any level contain the entry referred to by the supplied BEntry.
	Only entries that match the node flavor specified by \a nodeFlags are
	considered.
	\param entry a BEntry referring to the entry
	\param nodeFlags Any of the following:
		   - \c B_FILE_NODE: The entry must be a file.
		   - \c B_DIRECTORY_NODE: The entry must be a directory.
		   - \c B_SYMLINK_NODE: The entry must be a symbolic link.
		   - \c B_ANY_NODE: The entry may be of any kind.
	\return
	- \c true, if the BDirectory is properly initialized and the entry of the
	  matching kind could be found,
	- \c false, otherwise
*/
bool
BDirectory::Contains(const BEntry* entry, int32 nodeFlags) const
{
	// check, if the entry exists at all
	if (entry == NULL || !entry->Exists() || InitCheck() != B_OK)
		return false;

	if (nodeFlags != B_ANY_NODE) {
		// test the node kind
		bool result = false;
		if ((nodeFlags & B_FILE_NODE) != 0)
			result = entry->IsFile();
		if (!result && (nodeFlags & B_DIRECTORY_NODE) != 0)
			result = entry->IsDirectory();
		if (!result && (nodeFlags & B_SYMLINK_NODE) != 0)
			result = entry->IsSymLink();
		if (!result)
			return false;
	}

	// If the directory is initialized, get the canonical paths of the dir and
	// the entry and check, if the latter is a prefix of the first one.
	BPath dirPath(this, ".", true);
	BPath entryPath(entry);
	if (dirPath.InitCheck() != B_OK || entryPath.InitCheck() != B_OK)
		return false;

	uint32 dirLen = strlen(dirPath.Path());

	if (!strncmp(dirPath.Path(), entryPath.Path(), dirLen)) {
		// if the paths are identical, return a match to stay consistent with
		// BeOS behavior.
		if (entryPath.Path()[dirLen] == '\0' || entryPath.Path()[dirLen] == '/')
			return true;
	}
	return false;
}
Пример #9
0
void DirEnumerator::Readdir()
{
  namespace PP = acl::path;

  if (user && !PP::DirAllowed<PP::View>(*user, MakeVirtual(path))) 
  {
    return;
  }

  DIR* dp = opendir(path.CString());
  if (!dp) throw util::SystemError(errno);
  std::shared_ptr<DIR> dpGuard(dp, closedir);
  
  struct dirent de;
  struct dirent* dep;
  while (true)
  {
    readdir_r(dp, &de, &dep);
    if (!dep) break;

     if (!strcmp(de.d_name, ".") || !strcmp(de.d_name, "..")) continue;

    fs::RealPath entryPath(path / de.d_name);

    try
    {
      util::path::Status status(entryPath.ToString());
      totalBytes += status.Size();
      
      if (user)
      {
        fs::VirtualPath virtPath(MakeVirtual(entryPath));
        util::Error hideOwner;
        if (status.IsDirectory())
        {
          if (!PP::DirAllowed<PP::View>(*user, virtPath)) continue;
          hideOwner = PP::DirAllowed<PP::Hideowner>(*user, virtPath);
        }
        else
        {
          if (!PP::FileAllowed<PP::View>(*user, virtPath)) continue;
          hideOwner = PP::FileAllowed<PP::Hideowner>(*user, virtPath);
        }
        
        Owner owner(0, 0);
        if (!hideOwner && loadOwners) owner = GetOwner(entryPath);
        entries.emplace_back(fs::Path(de.d_name), status, owner);
      }
      else
      {
        Owner owner(0, 0);
        if (loadOwners) owner = GetOwner(entryPath);
        entries.emplace_back(fs::Path(de.d_name), status, owner);
      }
    }
    catch (const util::SystemError&)
    {
      continue;
    }
  }
}
Пример #10
0
void
FindWindow::FindResults(void)
{
	// This function is called from the FinderThread function, so locking is
	// required when accessing any member variables.
	Lock();
	bool canReplace = fReplaceButton->IsEnabled();
	EnableReplace(false);
	for (int32 i = fResultList->CountItems() - 1; i >= 0; i--)
	{
		// We don't want to hog the window lock, but we also don't want
		// tons of context switches, either. Yielding the lock every 5 items
		// should give us sufficient responsiveness.
		if (i % 5 == 0)
		{
			Unlock();
			Lock();
		}
		
		BListItem *item = fResultList->RemoveItem(i);
		delete item;
	}
	Unlock();

	ShellHelper shell;
	
	shell << "cd ";
	shell.AddEscapedArg(fWorkingDir);
	shell << "; pwd; find . -type f ";
	shell << "|xargs grep -n -H -s --binary-files=without-match ";
	// TODO check for PCRE invocation and pass in pcre flag to grep if so
	// TODO Ensure RE escaping also happens (E.g. open/close paran etc.)
	shell.AddEscapedArg(fFindBox->Text());
	
	if (fThreadQuitFlag)
		return;
	
	BString out;
	shell.RunInPipe(out, false);
	
	if (fThreadQuitFlag)
		return;
	
	BObjectList<BString> resultList(20, true);
	TokenizeToList(out.String(), resultList);
	
	Lock();
	
	for (int32 i = 0; i < resultList.CountItems(); i++)
	{
		// We don't want to hog the window lock, but we also don't want
		// tons of context switches, either. Yielding the lock every 5 items
		// should give us sufficient responsiveness.
		if (i % 5 == 0)
		{
			Unlock();
			Lock();
		}
		
		BString entryString(resultList.ItemAt(i)->String());
		
		BString filename(entryString);
		int32 pos = filename.FindFirst(":");
		if (pos < 0)
			continue;
		filename.Truncate(pos);
		if (filename.StartsWith("./"))
			filename.Remove(0,2);
		STRACE(2,("Truncated file name from grep: %s\n",filename.String()));
		
		BString lineString;
		entryString.CopyInto(lineString, pos + 1, entryString.CountChars() - pos);
		int32 pos2 = lineString.FindFirst(":");
		
		BString locationString;
		lineString.CopyInto(locationString, pos2 + 1, lineString.CountChars() - pos2);
		lineString.Truncate(pos2);
		
		DPath entryPath(fWorkingDir);
		entryPath << filename;
		
		BString fullPath(fWorkingDir);
		fullPath << "/" << filename;
		
		STRACE(2,("Full path: %s\n",fullPath.String()));
		
		DPath relPath(filename);
		
		fResultList->AddItem(new GrepListItem(fullPath,filename,
			entryPath.GetRef(), atol(lineString.String()),
			locationString.String()));
	}
	EnableReplace(true);
	
	if (fResultList->CountItems() == 0)
		fResultList->AddItem(new BStringItem(B_TRANSLATE("No matches found")));
	
	Unlock();
	
}