/// <summary> /// Add an empty dir /// </summary> /// <returns> the newly created dir </returns> private SqlDir __addDir(string dirName) { if ((dirName = checkInvalidChars(dirName)) == null) { SqlFsErrCode.CurrentError = FsErr.InvalidChars; return(null); } if (__isAlreadyExist(dirName)) { SqlFsErrCode.CurrentError = FsErr.NameAlreadyExists; return(null); } FsID newID = SqlDir.addDir(db, dirName, this.ID); if (newID.compare(SqlFsConst.INVALIDID) <= 0) { SqlFsErrCode.CurrentError = FsErr.NoNewIDForNewFsNode; return(null); } if (!updateChildList(SqlFsConst.FSOP.ADD, newID, FsID.toFsID(0))) { // delete entry just created SqlFs.deleteEntryByID(db, SqlFs.DBNAMES.FsBlock.ToString(), SqlFs.FSBLOCK.fsID.ToString(), newID); return(null); } return(SqlDir.getDir(db, fsLocker, newID)); }
/// @param [in] absolute dirPath -- e.g. "/path/to/dir" </param> private SqlDir __getDir(string dirPath) { if (SqlFsFunc.isNullOrEmpty(dirPath)) { SqlFsErrCode.CurrentError = FsErr.EmptyString; return(null); } if (!dirPath.StartsWith(SqlFsConst.STRPATHSEP)) // must start with '/' { SqlFsErrCode.CurrentError = FsErr.MustUseAbsolutePath; return(null); } dirPath = SqlFsFunc.Trim(dirPath, new char[] { SqlFsConst.PATHSEP }); SqlDir rootDir = RootDir; if (rootDir == null) { SqlFsErrCode.CurrentError = FsErr.CannotAccessRoot; return(null); } if (SqlFsFunc.isNullOrEmpty(dirPath)) // if empty after trim, it refers to root { return(rootDir); } return(rootDir.getDir(dirPath)); }
/// <summary> /// Get a fsNode from the result /// </summary> internal static SqlFsNode getFsNode(SQLiteDatabase db, SqlFsLocker fsLocker, Cursor c) { SqlFsNode fsNode = null; SqlFsConst.FSTYPE type = SqlFsConst.FSTYPE.toFSTYPE(c.getInt(SqlFs.FSBLOCK.fsType.ordinal())); if (type == SqlFsConst.FSTYPE.DIR) { fsNode = SqlDir.getDir(db, fsLocker, c); } else if (type == SqlFsConst.FSTYPE.FILE) { fsNode = SqlFile.getFile(db, fsLocker, c); } return(fsNode); }
/// <summary> /// Get list of subdirs only /// </summary> private List <SqlDir> __getSubDirs() { List <SqlDir> dirList = null; Cursor c = getEntryByName(null, SqlFsConst.FSTYPE.DIR); if (c != null) { c.moveToFirst(); dirList = new List <SqlDir>(c.Count); do { SqlDir dir = SqlDir.getDir(db, fsLocker, c); if (dir != null) { dirList.Add(dir); } } while (c.moveToNext()); c.close(); } return(dirList); }
/// <summary> /// Move itself to a destination path (absolute or relative) /// </summary> private bool __move(string destPath) { if (SqlFsFunc.isNullOrEmpty(destPath)) { SqlFsErrCode.CurrentError = FsErr.EmptyString; return(false); } // determine destination dir SqlDir destDir = null; if (destPath.StartsWith(SqlFsConst.STRPATHSEP)) { // absolute path SqlDir rootDir = (SqlDir)SqlFs.getFsNodeByID(db, fsLocker, SqlFsConst.ROOTDIRID); // get root destPath = SqlFsFunc.Trim(destPath, new char[] { SqlFsConst.PATHSEP }); // if empty after trim, it refers to root destDir = SqlFsFunc.isNullOrEmpty(destPath) ? rootDir : rootDir.getDir(destPath); } else { // relative path SqlDir parent = this.Parent; if (parent != null) { destDir = parent.getDir(destPath); } } if (destDir != null) { return(__move(destDir)); } SqlFsErrCode.CurrentError = FsErr.DestDirNotFound; return(false); }
internal static SqlDir getDir(SQLiteDatabase db, SqlFsLocker fsLocker, Cursor c) { FsID id = SqlFsFunc.getID(c, SqlFs.FSBLOCK.fsID.ordinal()); return(SqlDir.getDir(db, fsLocker, id)); }