Example #1
0
 void test_closed_p() {
   TS_ASSERT_EQUALS(d->closed_p(state), Qtrue);
   String* path = String::create(state, ".");
   d->open(state, path);
   TS_ASSERT_EQUALS(d->closed_p(state), Qfalse);
 }
Example #2
0
ssize_t file_size(Dir basedir, std::string fname) {
	return file_size(basedir.join(fname));
}
Example #3
0
 void test_close() {
   String* path = String::create(state, ".");
   d->open(state, path);
   TS_ASSERT_EQUALS(d->close(state), Qnil);
 }
Example #4
0
//----------------------------------------------------------------------------
size_t Dir::Traverse(DirTraverser& sink, const std::string &filespec,
	int flags) const
{
	size_t nFiles = 0;

	const std::string prefix = GetNameWithSep();

	if (flags & DIR_DIRS)
	{
		std::string dirname;
		for (bool cont = GetFirst(&dirname, "", (flags & ~(DIR_FILES | DIR_DOTDOT))|DIR_DIRS);
			cont; cont = cont && GetNext(&dirname))
		{
			const std::string fulldirname = prefix + dirname;

			switch (sink.OnDir(fulldirname))
			{
			default:
			case DIR_STOP:
				cont = false;
				break;

			case DIR_CONTINUE:
			{
								   Dir subdir;

								   bool ok;
								   do
								   {
									   ok = subdir.Open(fulldirname);
									   if (!ok)
									   {
										   // ask the user code what to do
										   bool tryagain;
										   switch (sink.OnOpenError(fulldirname))
										   {
										   default:
											   PX2_LOG_ERROR("unexpected OnOpenError() return value");
											   // fall through

										   case DIR_STOP:
											   cont = false;
											   // fall through

										   case DIR_IGNORE:
											   tryagain = false;
											   break;

										   case DIR_CONTINUE:
											   tryagain = true;
										   }

										   if (!tryagain)
											   break;
									   }
								   } while (!ok);

								   if (ok)
								   {
									   nFiles += subdir.Traverse(sink, filespec, flags);
								   }
			}
				break;

			case DIR_IGNORE:
				// nothing to do
				;
			}
		}
	}

	// now enum our own files
	if (flags & DIR_FILES)
	{
		flags &= ~DIR_DIRS;

		std::string filename;
		bool cont = GetFirst(&filename, filespec, flags);
		while (cont)
		{
			DirTraverseResult res = sink.OnFile(prefix + filename);
			if (res == DIR_STOP)
				break;

			assertion(res == DIR_CONTINUE, "unexpected OnFile() return value");

			nFiles++;

			cont = GetNext(&filename);
		}
	}

	return nFiles;

}
void ServerSideBrowserModel::setDirectory(const Dir& dir)
{
    m_xmmsClient->xformMediaBrowse(dir.url())(&ServerSideBrowserModel::getDirectoryItems, this,
                                              dir, std::placeholders::_1);
}
Example #6
0
 void test_create() {
   TS_ASSERT(kind_of<Dir>(d));
   TS_ASSERT(d->data()->nil_p());
 }
Example #7
0
//! Sets the current working directory
bool Dir::current( Dir const &dir )
{
  return chdir( dir.absolute().path() ) == 0;
}
Example #8
0
File *Dir::getFileFromSubdir(const char *subdir, const char *file)
{
    Dir *d = safecast<Dir*>(getDirByName(subdir, true, false)); // useSubtrees is irrelevant here
    return d ? d->getFile(file) : NULL;
}
Example #9
0
void FileSystemBrowser::directoryLoadFailed(const Dir& dir, const std::string& error)
{
    StatusArea::showMessage("Can't open %s : %s", dir.name(), error);
}
bool Collectiondb::load ( bool isDump ) {
	char dname[1024];
	// MDW: sprintf ( dname , "%s/collections/" , g_hostdb.m_dir );
	sprintf ( dname , "%s" , g_hostdb.m_dir );
	Dir d; 
	d.set ( dname );
	if ( ! d.open ()) return log("admin: Could not load collection config "
				     "files.");
	// note it
	log(LOG_INIT,"admin: Loading collection config files.");
	// . scan through all subdirs in the collections dir
	// . they should be like, "coll.main/" and "coll.mycollection/"
	char *f;
	while ( ( f = d.getNextFilename ( "*" ) ) ) {
		// skip if first char not "coll."
		if ( strncmp ( f , "coll." , 5 ) != 0 ) continue;
		// must end on a digit (i.e. coll.main.0)
		if ( ! is_digit (f[gbstrlen(f)-1]) ) continue;
		// point to collection
		char *coll = f + 5;
		// NULL terminate at .
		char *pp = strchr ( coll , '.' );
		if ( ! pp ) continue;
		*pp = '\0';
		// get collnum
		collnum_t collnum = atol ( pp + 1 );
		// add it
		if ( !addRec ( coll , NULL , 0 , false , collnum , isDump ,
			       true ) )
			return false;
	}
	// note it
	log(LOG_INIT,"admin: Loaded data for %li collections. Ranging from "
	    "collection #0 to #%li.",m_numRecsUsed,m_numRecs-1);
	// update the time
	updateTime();
	// don't clean the tree if just dumpin
	if ( isDump ) return true;
	// remove any nodes with illegal collnums
	Rdb *r;
	//r = g_indexdb.getRdb();
	//r->m_tree.cleanTree    ((char **)r->m_bases);
	r = g_posdb.getRdb();
	r->m_tree.cleanTree    ((char **)r->m_bases);
	//r = g_datedb.getRdb();
	//r->m_tree.cleanTree    ((char **)r->m_bases);

	r = g_titledb.getRdb();
	r->m_tree.cleanTree    ((char **)r->m_bases);
	//r = g_revdb.getRdb();
	//r->m_tree.cleanTree    ((char **)r->m_bases);
	//r = g_sectiondb.getRdb();
	//r->m_tree.cleanTree    ((char **)r->m_bases);
	//r = g_checksumdb.getRdb();
	//r->m_tree.cleanTree    ((char **)r->m_bases);
	//r = g_tfndb.getRdb();
	//r->m_tree.cleanTree    ((char **)r->m_bases);
	r = g_spiderdb.getRdb();
	r->m_tree.cleanTree    ((char **)r->m_bases);
	r = g_doledb.getRdb();
	r->m_tree.cleanTree    ((char **)r->m_bases);
	// success
	return true;
}
Example #11
0
void ServerSideBrowser::onDirectoryLoaded(const Dir& dir)
{
    // FIXME: Path may be too long to display
    std::string path = dir.protocol() == "file" ? dir.path() : dir.url();
    setName(std::string("Server side browser: ").append(path));
}
Example #12
0
///	\brief	Mcd Draw 함수
void	NCurses_Mcd::Draw()
{
	WINDOW*	pWin = GetWin();

	vector<chtype> vLineChType;
	
    int nRow = 0, nCol = 0, nODep=0;
	int j = 0;

	DrawInit();

	Dir *pCur = (*_pCur);
	
	if (pCur->nRow - _nSRow > height-3) _nSRow = pCur->nRow-height+3;
	if (pCur->nDepth - _nSCol > _nRowSize) _nSCol = pCur->nDepth - _nRowSize;
	if (pCur->nRow - _nSRow < 0) _nSRow = pCur->nRow;
	if (pCur->nDepth - _nSCol < 1)
	{
		 _nSCol = pCur->nDepth-1;
		 if (_nSCol == -1) _nSCol=0;
	}

	// 화면 지우기
	if (!_sStrSearch.empty())
	{
		setcol(_tMCDColor, pWin);
		mvwprintw(pWin, 0, width-25, "Search : [%-10s]", _sStrSearch.c_str());
	}

	setcol(_tMCDColor, pWin);
	mvwprintw(pWin, height-1, 2, "Path [ %s ]", isKorCode(pCur->Path()).c_str() );

	int nButtonCount = 0;

	Dir *pNode = NULL;
	
	for (pDirIterator i=_pOrder.begin(); i!=_pOrder.end(); i++)
	{
		pNode = *i;

		if (nODep < pNode->nDepth)
			vLineChType.push_back(VLINE);
		else
			while(pNode->nDepth < nODep)
			{
				nODep--;
				vLineChType.pop_back();
			}
		
		nODep = pNode->nDepth;
		nCol  = pNode->nDepth;
		nRow  = pNode->nRow;

		// 출력 다했으면 종료		
		if (pNode->nDepth != 0 && pNode->pParentDir->vNode.back()==pNode)
			vLineChType[nCol-1] = ' ';

		//LOG_WRITE("nODep [%d] nCol [%d] nRow [%d] _nSRow [%d] _nSCol [%d]", nODep, nCol, nRow, _nSRow, _nSCol);
		//LOG_WRITE("NCurses::Draw pNode->nDepth [%d]", pNode->nDepth);
			
		if (nRow - _nSRow > height-3) break;
		if (nRow - _nSRow < 0) continue;

		if (pNode != _pRoot && pNode->pParentDir->vNode.front()!= pNode)
		{
			for (int t = _nSCol; t < nCol && t < _nSCol+_nRowSize; t++)
			{
				setcol(_tMCDLine, pWin);
				mvwaddch(pWin, nRow-_nSRow+1, ColLocation[t-_nSCol+1], vLineChType[t]);
			}
		}
	
		if (nCol - _nSCol > _nRowSize ) continue;
		if (_nSCol != 0 && nCol - _nSCol < 1 ) continue;
		
		if (pNode->nDepth==0)
		{// 루트라면
			McdDirButton* pDirButton = _vDirButtonList[nButtonCount];

			pDirButton->SetForm((Form*)this);
			pDirButton->height = 1;
			pDirButton->width = 12;
			pDirButton->x = nRow-_nSRow+1;
			pDirButton->y = 1;

			// 선을 하나 더 긋고 이름 출력 
			if (pNode == pCur)
				pDirButton->SetDir(pNode, _bFocus);
			else
				pDirButton->SetDir(pNode, false);

			pDirButton->Show();
			nButtonCount++;
		}		
		else
		{// 아니라면
			if (pNode->pParentDir->vNode.size() > 1)
			{	
				// 디렉토리가 하나가 아닐때 
				if (pNode->pParentDir->vNode.front()==pNode)
				{	
					// 첫번째 노드 
					setcol(_tMCDLine, pWin);
					wmove(pWin, nRow-_nSRow+1, ColLocation[nCol-_nSCol]);
					waddch(pWin, TTEE);
				}
				else
				{
					// 그 이외의 디렉토리 
					wmove(pWin, nRow-_nSRow+1, ColLocation[nCol-_nSCol]);

					setcol(_tMCDLine, pWin);
					if (pNode->pParentDir->vNode.back()==pNode)
						waddch(pWin, LLCORNER);
					else 
						waddch(pWin, LTEE); 
				}	
			}
			else
			{
				wmove(pWin, nRow-_nSRow+1, ColLocation[nCol-_nSCol]);
				setcol(_tMCDLine, pWin);
				waddch(pWin, HLINE); 
			}
			
			setcol(_tMCDHighLight, pWin);
			if (pNode->bCheck == false)
			{
				waddch(pWin, '+');
			}
			else
			{
				waddch(pWin, HLINE);
			}

			//LOG_WRITE("NCurses_Mcd::Draw nButtonCount [%d] [%d]", nButtonCount, _vDirButtonList.size());

			McdDirButton* pDirButton = _vDirButtonList[nButtonCount];

			pDirButton->SetForm((Form*)this);
			pDirButton->height = 1;
			pDirButton->width = 12;
			pDirButton->x = ColLocation[nCol-_nSCol]+2;
			pDirButton->y = nRow-_nSRow+1;

			// 선을 하나 더 긋고 이름 출력 
			if (pNode == pCur)
				pDirButton->SetDir(pNode, _bFocus);
			else
				pDirButton->SetDir(pNode, false);

			pDirButton->Show();
			nButtonCount++;
		}
	}
	wnoutrefresh(_pWin);
}
Example #13
0
 void test_close() {
   String* path = String::create(state, ".");
   d->open(state, path);
   TS_ASSERT_EQUALS(d->close(state), Qtrue);
   TS_ASSERT(d->data()->nil_p());
 }
Example #14
0
 void test_open() {
   String* path = String::create(state, ".");
   TS_ASSERT_EQUALS(d->open(state, path), Qnil);
   TS_ASSERT(!d->data()->nil_p());
 }
Example #15
0
 void tearDown() {
   if(!d->closed_p(state)->true_p()) d->close(state);
   destroy();
 }
// . sets m_fileOffset and m_bf
// . returns false and sets g_errno on error
// . returns false if nothing to read too... but does not set g_errno
bool ImportState::setCurrentTitleFileAndOffset ( ) {

	// leave m_bf and m_fileOffset alone if there is more to read
	if ( m_fileOffset < m_bfFileSize )
		return true;

	CollectionRec *cr = g_collectiondb.getRec ( m_collnum );
	if ( ! cr ) return false;

	log("import: import finding next file");
	
	// if ( m_offIsValid ) {
	// 	//*off = m_fileOffset;
	// 	return &m_bf; 
	// }
	//m_offIsValid = true;

	// look for titledb0001.dat etc. files in the 
	// workingDir/inject/ subdir
	SafeBuf ddd;
	ddd.safePrintf("%sinject",cr->m_importDir.getBufStart());
	// now use the one provided. we should also provide the # of threads
	if ( cr->m_importDir.getBufStart() && 
	     cr->m_importDir.getBufStart()[0] ) {
		ddd.reset();
		ddd.safeStrcpy ( cr->m_importDir.getBufStart() );
	}

	//
	// assume we are the first filename
	// set s_fileId to the minimum
	//
	Dir dir;
	dir.set(ddd.getBufStart());

	if ( ! dir.open() ) return false;

	// assume none
	long minFileId = -1;

	// getNextFilename() writes into this
	char pattern[64]; strcpy ( pattern , "titledb*" );
	char *filename;
	while ( ( filename = dir.getNextFilename ( pattern ) ) ) {
		// filename must be a certain length
		long filenameLen = gbstrlen(filename);
		// we need at least "titledb0001.dat"
		if ( filenameLen < 15 ) continue;
		// ensure filename starts w/ our m_dbname
		if ( strncmp ( filename , "titledb", 7 ) != 0 )
			continue;
		// skip if not .dat file
		if ( ! strstr ( filename , ".dat" ) )
			continue;
		// then a 4 digit number should follow
		char *s = filename + 7;
		if ( ! isdigit(*(s+0)) ) continue;
		if ( ! isdigit(*(s+1)) ) continue;
		if ( ! isdigit(*(s+2)) ) continue;
		if ( ! isdigit(*(s+3)) ) continue;
		// convert digit to id
		long id = atol(s);
		// . do not accept files we've already processed
		// . -1 means we haven't processed any yet
		if ( m_bfFileId >= 0 && id <= m_bfFileId ) continue;
		// the min of those we haven't yet processed/injected
		if ( id < minFileId || minFileId < 0 ) minFileId = id;
	}

	// get where we left off
	if ( ! m_loadedPlaceHolder ) {
		// read where we left off from file if possible
		char fname[256];
		sprintf(fname,"%slasttitledbinjectinfo.dat",g_hostdb.m_dir);
		SafeBuf ff;
		ff.fillFromFile(fname);
		if ( ff.length() > 1 ) {
			m_loadedPlaceHolder = true;
			// get the placeholder
			sscanf ( ff.getBufStart() 
				 , "%llu,%lu"
				 , &m_fileOffset
				 , &minFileId
				 );
		}
	}

	// if no files! return false to indicate we are done
	if ( minFileId == -1 ) return false;

	// set up s_bf then
	//if ( m_bfFileId != minFileId ) {
	SafeBuf tmp;
	tmp.safePrintf("titledb%04li-000.dat"
		       //,dir.getDirname()
		       ,minFileId);
	m_bf.set ( dir.getDirname() ,tmp.getBufStart() );
	if ( ! m_bf.open( O_RDONLY ) ) {
		log("inject: import: could not open %s%s for reading",
		    dir.getDirname(),tmp.getBufStart());
		return false;
	}
	m_bfFileId = minFileId;
	// reset ptr into file
	//*off = 0;
	// and set this
	m_bfFileSize = m_bf.getFileSize();

	m_fileOffset = 0;
	//}

	log("import: importing from file %s",m_bf.getFilename());

	return true;//&m_bf;
}
Example #17
0
 void test_open() {
   String* path = String::create(state, ".");
   TS_ASSERT_EQUALS(d->open(state, path), Qtrue);
 }
Example #18
0
 void tearDown() {
   if(!d->closed_p(state)->true_p()) d->close(state);
   delete state;
 }