/// <summary> /// Check if a dir/file name contains invalid character /// </summary> /// @param [in] name -- contains dir/file name to be checked /// on return, it contains a whitespace-trimmed version /// </param> /// <returns> null -- contains invalid characters </returns> /// <returns> String -- may be modified name </returns> protected internal virtual string checkInvalidChars(string name) { if (SqlFsFunc.isNullOrEmpty(name)) { return(null); } string trimmedStr = SqlFsFunc.Trim(name, SqlFsConst.CHARSTOTRIM); if (SqlFsFunc.isNullOrEmpty(trimmedStr)) // check once again { return(null); } if (SqlFsFunc.indexOfAny(trimmedStr, SqlFsConst.INVALIDCHARS) >= 0) { return(null); } if (trimmedStr.Equals(SqlFsConst.CURDIR)) // can't be '.' { return(null); } if (trimmedStr.Equals(SqlFsConst.PARENTDIR)) // can't be '..' { return(null); } return(trimmedStr); }
/// @param [in] absolute filePath -- e.g. "/path/to/file" </param> private SqlFile __getFile(string filePath) { if (SqlFsFunc.isNullOrEmpty(filePath)) { SqlFsErrCode.CurrentError = FsErr.EmptyString; return(null); } if (!filePath.StartsWith(SqlFsConst.STRPATHSEP)) // must start with '/' { SqlFsErrCode.CurrentError = FsErr.MustUseAbsolutePath; return(null); } filePath = SqlFsFunc.Trim(filePath, new char[] { SqlFsConst.PATHSEP }); SqlDir rootDir = RootDir; if (rootDir == null) { SqlFsErrCode.CurrentError = FsErr.CannotAccessRoot; return(null); } return(rootDir.getFile(filePath)); }
/// <summary> /// Test if a absolute path (dir/file) exists /// </summary> private bool __exists(string path) { if (SqlFsFunc.isNullOrEmpty(path)) { SqlFsErrCode.CurrentError = FsErr.EmptyString; return(false); } if (!path.StartsWith(SqlFsConst.STRPATHSEP)) // must start with '/' { SqlFsErrCode.CurrentError = FsErr.MustUseAbsolutePath; return(false); } path = SqlFsFunc.Trim(path, new char[] { SqlFsConst.PATHSEP }); if (SqlFsFunc.isNullOrEmpty(path)) // if empty after trim, it refers to root { return(true); } SqlDir rootDir = RootDir; if (rootDir == null) { SqlFsErrCode.CurrentError = FsErr.CannotAccessRoot; return(false); } SqlFsNode fsNode = rootDir.getFsNode(path); return(fsNode != null); }
/// @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> /// 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); }