public FilesystemSpiegel() { this.drvInfo = new DriveInfo(@"C:\"); this.root = new FSSpiegelDirectory(null, new System.IO.DirectoryInfo(this.drvInfo.RootDirectory.FullName)); }
public FSSpiegelDirectory(IFuserFilesystemDirectory parentDir, DirectoryInfo realDir) { this.realDir = realDir; this.content = null; this.flag = false; this.parentDir = parentDir; }
/// <summary> /// Removes the lock for deleting directories for all directories (recursive up to the root). /// </summary> /// <param name="blockDirectory"></param> /// <param name="flock"></param> private static void ReleaseBlockDeletePermission(IFuserFilesystemDirectory blockDirectory, FileLockItem flock) { if (blockDirectory == null) { return; // Abort criterion for recursive method. } if (flock == null) { return; } try { FileLockManager lockMgr = blockDirectory.Filelock; if (lockMgr == null) { return; } lock (lockMgr) { lockMgr.ReleaseBlockDeletePermission(flock); } } catch { return; } ReleaseBlockDeletePermission(blockDirectory.Parent, flock); // recursively reset to root for all }
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); }
public FuserPathResolveResult(FSException exception) { this.path = null; this.root = null; this.curDir = null; this.pItemname = ""; this.pHasError = true; this.errorcode = exception.Error; }
public FuserPathResolveResult(IFuserFilesystemDirectory root, string path) { this.path = path; this.root = root; this.curDir = root; this.pItemname = ""; this.pHasError = false; this.errorcode = Win32Returncode.SUCCESS; }
public SimSubdirectory(IFuserFilesystemDirectory parentDir, string name) { this.directoryContent = new List <IFuserFilesystemItem>(); this.name = name; this.attrA = false; this.parentDir = parentDir; this.timeA = DateTime.Now; this.timeC = this.timeA; this.timeW = this.timeA; }
public void MoveTo(IFuserFilesystemItem item, IFuserFilesystemDirectory destination, string newname) { if (item is SimRoot) { throw new Exception("Access error"); } if (item is SimFile) { SimFile vFile = (SimFile)item; if (vFile.Name != newname) { vFile.SetNewName(newname); } } if (item is SimSubdirectory) { SimSubdirectory vDir = (SimSubdirectory)item; if (vDir.Name != newname) { vDir.SetNewName(newname); } } if (destination == null) { return; } if (destination is SimSubdirectory) { SimSubdirectory vDstDir = (SimSubdirectory)destination; directoryContent.Remove(item); vDstDir.AddItem(item); return; } if (destination is SimRoot) { SimRoot vDstRoot = (SimRoot)destination; directoryContent.Remove(item); vDstRoot.AddItem(item); return; } throw new Exception("Mode not supported"); }
public FileHandler(string filename) { this.pFilename = filename; this.curItem = null; this.curDir = null; this.UseOPLocks = true;// by default, OPLocks must be checked this.pIsOpenRead = false; this.pIsOpenWrite = false; this.pData = null; this.pLocks = new List <FileLockItem>(); this.pLocks.Clear(); this.pFileLastAccess = new FileLastAccessControl(); }
/// <summary> /// Release a filelock /// </summary> /// <param name="fileHandle"></param> /// <param name="item"></param> public static void FilelockRelease(FileHandler fileHandle, IFuserFilesystemItem item) { try { if (fileHandle == null || item == null) { return; } FileLockManager lockMgr = item.Filelock; FileLockItem[] locks = null; lock (fileHandle) { locks = fileHandle.GetFileLockList(); } if (locks != null) { IFuserFilesystemDirectory dirItem = null; if (item is IFuserFilesystemDirectory) { dirItem = (IFuserFilesystemDirectory)item; } lock (lockMgr) { foreach (FileLockItem lItem in locks) { lockMgr.UnregisterLock(lItem); if (dirItem != null) { ReleaseBlockDeletePermission(dirItem, lItem); } } } } } catch { return; } }
/// <summary> /// Checks whether the specified directory is flagged for deletion. /// </summary> /// <param name="vDir"></param> /// <returns></returns> public static bool CheckIsDirectoryDeletedOnClose(IFuserFilesystemDirectory vDir) { // TODO: check if a certain error code must be returned when calling this function if (vDir == null) { return(false); } if (vDir.Filelock == null) { return(false); } bool selDeleted = false; try { FileLockManager lockMgr = vDir.Filelock; lock (lockMgr) { selDeleted = lockMgr.DeleteOnClose; } } catch { return(false); } return(selDeleted); }
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); }
public void MoveTo(IFuserFilesystemItem item, IFuserFilesystemDirectory destination, string newname) { throw new NotImplementedException(); }
public void SetParent(IFuserFilesystemDirectory newParent) { this.parentDir = newParent; }
public FilesystemSimulate() { this.root = getnewRoot(); }