Inheritance: Structure
Beispiel #1
0
        public bool Copy(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace = true)
        {
            Volume sourceVolume      = GetVolumeFromPath(sourcePath);
            Volume destinationVolume = GetVolumeFromPath(destinationPath);

            VolumeItem source      = sourceVolume.Open(sourcePath);
            VolumeItem destination = destinationVolume.Open(destinationPath);

            if (source == null)
            {
                throw new KOSPersistenceException("Path does not exist: " + sourcePath);
            }

            if (source is VolumeDirectory)
            {
                if (destination is VolumeFile)
                {
                    throw new KOSPersistenceException("Can't copy directory into a file");
                }

                if (destination == null)
                {
                    destination = destinationVolume.CreateDirectory(destinationPath);
                }
                else if (!sourcePath.IsRoot)
                {
                    destinationPath = destinationPath.Combine(sourcePath.Name);
                    destination     = destinationVolume.OpenOrCreateDirectory(destinationPath);
                }

                if (destination == null)
                {
                    throw new KOSException("Path was expected to point to a directory: " + destinationPath);
                }

                return(CopyDirectory(sourcePath, destinationPath, verifyFreeSpace));
            }
            else
            {
                if (destination is VolumeFile || destination == null)
                {
                    Volume targetVolume = GetVolumeFromPath(destinationPath);
                    return(CopyFile(source as VolumeFile, destinationPath, targetVolume, verifyFreeSpace));
                }
                else
                {
                    return(CopyFileToDirectory(source as VolumeFile, destination as VolumeDirectory, verifyFreeSpace));
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 // Volumes, VolumeItems and strings
 public GlobalPath GlobalPathFromObject(object pathObject)
 {
     if (pathObject is Volume)
     {
         GlobalPath p = GlobalPath.FromVolumePath(VolumePath.EMPTY, GetVolumeRawIdentifier(pathObject as Volume));
         SafeHouse.Logger.Log("Path from volume: " + p);
         return(p);
     }
     else if (pathObject is VolumeItem)
     {
         VolumeItem volumeItem = pathObject as VolumeItem;
         return(GlobalPath.FromVolumePath(volumeItem.Path, GetVolumeRawIdentifier(volumeItem.Volume)));
     }
     else
     {
         return(GlobalPathFromString(pathObject.ToString()));
     }
 }
Beispiel #4
0
        public bool IsRoomFor(VolumePath path, FileContent fileContent)
        {
            VolumeItem existing = Open(path);

            if (existing is VolumeDirectory)
            {
                throw new KOSPersistenceException("'" + path + "' is a directory");
            }

            VolumeFile existingFile = existing as VolumeFile;

            int usedByThisFile = 0;

            if (existingFile != null)
            {
                usedByThisFile = existingFile.ReadAll().Size;
            }

            return(INFINITE_CAPACITY == FreeSpace || FreeSpace + usedByThisFile >= fileContent.Size);
        }
Beispiel #5
0
        public Structure OpenSafe(string pathString, bool ksmDefault = false)
        {
            VolumeItem item = Open(VolumePath.FromString(pathString), ksmDefault);

            return(item != null ? (Structure)item : BooleanValue.False);
        }