예제 #1
0
파일: SqlDir.cs 프로젝트: thelan/sqlitefs
        /// <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));
        }
예제 #2
0
        ///  @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));
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
파일: SqlDir.cs 프로젝트: thelan/sqlitefs
        /// <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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
파일: SqlDir.cs 프로젝트: thelan/sqlitefs
        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));
        }