public bool Move(GlobalPath sourcePath, GlobalPath destinationPath) { if (sourcePath.IsRoot) { throw new KOSPersistenceException("Can't move root directory: " + sourcePath); } if (sourcePath.IsParent(destinationPath)) { throw new KOSPersistenceException("Can't move directory to a subdirectory of itself: " + destinationPath); } Volume sourceVolume = GetVolumeFromPath(sourcePath); Volume destinationVolume = GetVolumeFromPath(destinationPath); bool verifyFreeSpace = sourceVolume != destinationVolume; if (!Copy(sourcePath, destinationPath, verifyFreeSpace)) { return(false); } if (!sourceVolume.Delete(sourcePath)) { throw new KOSPersistenceException("Can't remove: " + sourcePath); } return(true); }
protected bool CopyDirectory(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace) { if (sourcePath.IsParent(destinationPath)) { throw new KOSPersistenceException("Can't copy directory to a subdirectory of itself: " + destinationPath); } Volume sourceVolume = GetVolumeFromPath(sourcePath); Volume destinationVolume = GetVolumeFromPath(destinationPath); VolumeDirectory source = sourceVolume.Open(sourcePath) as VolumeDirectory; VolumeItem destinationItem = destinationVolume.Open(destinationPath); if (destinationItem is VolumeFile) { throw new KOSPersistenceException("Can't copy directory into a file"); } VolumeDirectory destination = destinationItem as VolumeDirectory; if (destination == null) { destination = destinationVolume.CreateDirectory(destinationPath); } var l = source.List(); foreach (KeyValuePair <string, VolumeItem> pair in l) { if (pair.Value is VolumeDirectory) { if (!CopyDirectory(sourcePath.Combine(pair.Key), destinationPath.Combine(pair.Key), verifyFreeSpace)) { return(false); } } else { if (!CopyFileToDirectory(pair.Value as VolumeFile, destination, verifyFreeSpace)) { return(false); } } } return(true); }
protected bool CopyDirectory(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace) { if (sourcePath.IsParent(destinationPath)) { throw new KOSPersistenceException("Can't copy directory to a subdirectory of itself: " + destinationPath); } Volume sourceVolume = GetVolumeFromPath(sourcePath); Volume destinationVolume = GetVolumeFromPath(destinationPath); VolumeDirectory source = sourceVolume.Open(sourcePath) as VolumeDirectory; VolumeItem destinationItem = destinationVolume.Open(destinationPath); if (destinationItem is VolumeFile) { throw new KOSPersistenceException("Can't copy directory into a file"); } VolumeDirectory destination = destinationItem as VolumeDirectory; if (destination == null) { destination = destinationVolume.CreateDirectory(destinationPath); } var l = source.List(); foreach (KeyValuePair<string, VolumeItem> pair in l) { if (pair.Value is VolumeDirectory) { if (!CopyDirectory(sourcePath.Combine(pair.Key), destinationPath.Combine(pair.Key), verifyFreeSpace)) { return false; } } else { if (!CopyFileToDirectory(pair.Value as VolumeFile, destination, verifyFreeSpace)) { return false; } } } return true; }
public bool Move(GlobalPath sourcePath, GlobalPath destinationPath) { if (sourcePath.IsRoot) { throw new KOSPersistenceException("Can't move root directory: " + sourcePath); } if (sourcePath.IsParent(destinationPath)) { throw new KOSPersistenceException("Can't move directory to a subdirectory of itself: " + destinationPath); } Volume sourceVolume = GetVolumeFromPath(sourcePath); Volume destinationVolume = GetVolumeFromPath(destinationPath); bool verifyFreeSpace = sourceVolume != destinationVolume; if (!Copy(sourcePath, destinationPath, verifyFreeSpace)) { return false; } if (!sourceVolume.Delete(sourcePath)) { throw new KOSPersistenceException("Can't remove: " + sourcePath); } return true; }