Example #1
0
        ///  @param [in] relative dirPath -- e.g. "path/to/dir" </param>
        private SqlFsNode __getFsNode(string path)
        {
            if (SqlFsFunc.isNullOrEmpty(path))
            {
                SqlFsErrCode.CurrentError = FsErr.EmptyString;
                return(null);
            }

            if (path.StartsWith(SqlFsConst.STRPATHSEP))        // must *NOT* start with '/'
            {
                SqlFsErrCode.CurrentError = FsErr.MustUseRelativePath;
                return(null);
            }

            if (path.EndsWith(SqlFsConst.STRPATHSEP))        // trim trailing '/'
            {
                path = SqlFsFunc.trimEnd(path, new char[] { SqlFsConst.PATHSEP });
            }

            string[] pathSeg = path.Split(SqlFsConst.STRPATHSEP, true);
            if (pathSeg == null || pathSeg.Length <= 0)
            {
                SqlFsErrCode.CurrentError = FsErr.SplitPathErr;
                return(null);
            }

            SqlFsNode curNode = this;

            // start looping to target node
            for (int i = 0; i < pathSeg.Length; ++i)
            {
                if (SqlFsFunc.isNullOrEmpty(pathSeg[i]))           // to prevent empty space between separator
                {
                    continue;
                }

                curNode = ((SqlDir)curNode).__getChild(pathSeg[i]);
                if (curNode == null)
                {
                    SqlFsErrCode.CurrentError = FsErr.ChildNotFound;
                    break;
                }

                if (!curNode.Dir && i != pathSeg.Length - 1)           // if a file but not reach the end yet
                {
                    curNode = null;
                    SqlFsErrCode.CurrentError = FsErr.NotDirInPath;
                    break;
                }
            }

            return(curNode);
        }
Example #2
0
        ///  @param [in] relative 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 *NOT* start with '/'
            {
                SqlFsErrCode.CurrentError = FsErr.MustUseRelativePath;
                return(null);
            }

            if (dirPath.EndsWith(SqlFsConst.STRPATHSEP))        // trim trailing '/'
            {
                dirPath = SqlFsFunc.trimEnd(dirPath, new char[] { SqlFsConst.PATHSEP });
            }

            string[] dirSeg = dirPath.Split(SqlFsConst.STRPATHSEP, true);
            if (dirSeg == null || dirSeg.Length <= 0)
            {
                SqlFsErrCode.CurrentError = FsErr.SplitPathErr;
                return(null);
            }

            SqlFsNode curNode = this;

            // start looping to target dir
            foreach (string dir in dirSeg)
            {
                if (SqlFsFunc.isNullOrEmpty(dir))           // to prevent empty space between separator
                {
                    continue;
                }

                curNode = ((SqlDir)curNode).__getChild(dir);
                if (curNode == null || !curNode.Dir)
                {
                    curNode = null;
                    SqlFsErrCode.CurrentError = FsErr.ChildNotFound;
                    break;
                }
            }


            return((SqlDir)curNode);
        }