** Advance an fsdir_cursor to its next row of output. */
| 6148 | ** Advance an fsdir_cursor to its next row of output. |
| 6149 | */ |
| 6150 | static int fsdirNext(sqlite3_vtab_cursor *cur){ |
| 6151 | fsdir_cursor *pCur = (fsdir_cursor*)cur; |
| 6152 | mode_t m = pCur->sStat.st_mode; |
| 6153 | |
| 6154 | pCur->iRowid++; |
| 6155 | if( S_ISDIR(m) ){ |
| 6156 | /* Descend into this directory */ |
| 6157 | int iNew = pCur->iLvl + 1; |
| 6158 | FsdirLevel *pLvl; |
| 6159 | if( iNew>=pCur->nLvl ){ |
| 6160 | int nNew = iNew+1; |
| 6161 | sqlite3_int64 nByte = nNew*sizeof(FsdirLevel); |
| 6162 | FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte); |
| 6163 | if( aNew==0 ) return SQLITE_NOMEM; |
| 6164 | memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl)); |
| 6165 | pCur->aLvl = aNew; |
| 6166 | pCur->nLvl = nNew; |
| 6167 | } |
| 6168 | pCur->iLvl = iNew; |
| 6169 | pLvl = &pCur->aLvl[iNew]; |
| 6170 | |
| 6171 | pLvl->zDir = pCur->zPath; |
| 6172 | pCur->zPath = 0; |
| 6173 | pLvl->pDir = opendir(pLvl->zDir); |
| 6174 | if( pLvl->pDir==0 ){ |
| 6175 | fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath); |
| 6176 | return SQLITE_ERROR; |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | while( pCur->iLvl>=0 ){ |
| 6181 | FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl]; |
| 6182 | struct dirent *pEntry = readdir(pLvl->pDir); |
| 6183 | if( pEntry ){ |
| 6184 | if( pEntry->d_name[0]=='.' ){ |
| 6185 | if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue; |
| 6186 | if( pEntry->d_name[1]=='\0' ) continue; |
| 6187 | } |
| 6188 | sqlite3_free(pCur->zPath); |
| 6189 | pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name); |
| 6190 | if( pCur->zPath==0 ) return SQLITE_NOMEM; |
| 6191 | if( fileLinkStat(pCur->zPath, &pCur->sStat) ){ |
| 6192 | fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath); |
| 6193 | return SQLITE_ERROR; |
| 6194 | } |
| 6195 | return SQLITE_OK; |
| 6196 | } |
| 6197 | closedir(pLvl->pDir); |
| 6198 | sqlite3_free(pLvl->zDir); |
| 6199 | pLvl->pDir = 0; |
| 6200 | pLvl->zDir = 0; |
| 6201 | pCur->iLvl--; |
| 6202 | } |
| 6203 | |
| 6204 | /* EOF */ |
| 6205 | sqlite3_free(pCur->zPath); |
| 6206 | pCur->zPath = 0; |
| 6207 | return SQLITE_OK; |
nothing calls this directly
no test coverage detected