private Win32Returncode pLastErrorCode; // always returns an error code that best fits. public PathResolver(IFuserFilesystemDirectory root, string path) { this.pPath = null; this.pFileitem = null; this.pPathInvalid = true; this.pLastErrorCode = Win32Returncode.DEFAULT_UNKNOWN_ERROR; resolve(root, path); }
private void resolve(IFuserFilesystemDirectory root, string path) { FuserPathResolveResult vpr = null; try { vpr = ResolvePath(root, path); this.pPath = vpr; if (vpr.returncode != Win32Returncode.SUCCESS) { this.pPathInvalid = true; this.pLastErrorCode = vpr.returncode; return; } } catch { // should never occur this.pPathInvalid = true; this.pLastErrorCode = Win32Returncode.ERROR_PATH_NOT_FOUND; this.pPath = null; return; } if (vpr != null) { if (vpr.HasError) { vpr = null; } } if (vpr != null) { if (vpr.returncode != Win32Returncode.SUCCESS) { vpr = null; } } if (vpr == null) { this.pPathInvalid = true; this.pLastErrorCode = Win32Returncode.ERROR_PATH_NOT_FOUND; this.pPath = null; } else { this.pPathInvalid = false; this.pLastErrorCode = Win32Returncode.DEFAULT_UNKNOWN_ERROR; this.pFileitem = null; if (vpr.currentDirectory == root && vpr.itemname == "") { this.pFileitem = root; } else { if (vpr.itemname == "") { // path not found this.pLastErrorCode = Win32Returncode.ERROR_PATH_NOT_FOUND; this.pPathInvalid = true; } else { try { lock (vpr.currentDirectory) { this.pFileitem = vpr.currentDirectory.GetItem(vpr.itemname); } } catch { this.pFileitem = null; } } } } }
private FuserPathResolveResult ResolvePath(IFuserFilesystemDirectory root, string path) { FuserPathResolveResult ret = new FuserPathResolveResult(root, path); IFuserFilesystemDirectory currentdirectory = root; IFuserFilesystemItem vItem; string lastItem = ""; string p; if (path == "") { return(new FuserPathResolveResult(new FSException(Win32Returncode.ERROR_INVALID_NAME))); } if (path.Length < 1) { return(new FuserPathResolveResult(new FSException(Win32Returncode.ERROR_INVALID_NAME))); } if (path.Substring(0, 1) != PATHDELIMITTER) { return(new FuserPathResolveResult(new FSException(Win32Returncode.ERROR_INVALID_NAME))); } try { path = path.Substring(1); // Remove starting \ if (path != "") { string[] part = path.Split(PATHDELIMITTER.ToCharArray()[0]); lastItem = part[part.Length - 1]; // select last item if (!PathValidateCheckItemname(lastItem, true)) { throw new Exception("Invalid Path"); } for (int i = 0; i < (part.Length - 1); i++) { p = part[i].Trim(); if (PathValidateCheckItemname(p, false)) { vItem = null; lock (currentdirectory) { vItem = currentdirectory.GetItem(p); } if (vItem == null) { throw new KeyNotFoundException(); } if (!(vItem is IFuserFilesystemDirectory)) { throw new Exception("Invalid path"); } currentdirectory = (IFuserFilesystemDirectory)vItem; } else { throw new Exception("Invalid Path"); } } } } catch (FSException fse) { return(new FuserPathResolveResult(fse)); } catch (Exception e) { e.ToString(); return(new FuserPathResolveResult(new FSException(Win32Returncode.ERROR_PATH_NOT_FOUND))); } ret.currentDirectory = currentdirectory; ret.itemname = lastItem; return(ret); }