Esempio n. 1
0
 /// <summary>
 /// Deletes the file
 /// </summary>
 public void Delete()
 {
     if (!WhatIf)
     {
         File.Delete(HelixUtil.PathNative(this.FullName));
     }
     ((IFSDirectoryCore)Parent).Remove(this);
     this.Exists = false;
 }
Esempio n. 2
0
        public void FindChanges_AddsInOrderParentToChildren()
        {
            Decr1.UpdateTo("file1.txt < aa", "zz/file2.txt");

            using (var pair = DirectoryPair.Open(Decr1.DirectoryPath, Encr1.DirectoryPath, DerivedBytesProvider.FromPassword("password"), true, HelixFileVersion.UnitTest))
            {
                for (int i = 0; i < 100; i++)
                {
                    var changes     = pair.FindChanges();
                    var parentIndex = changes.FindIndex(c => c.DecrFileName == "zz");
                    var childIndex  = changes.FindIndex(c => HelixUtil.PathNative(c.DecrFileName) == HelixUtil.PathNative("zz/file2.txt"));
                    Assert.IsTrue(parentIndex < childIndex, "Parent Directory Add did not come before Child File Add");
                }
            }
        }
Esempio n. 3
0
        public string PathFull(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            path = HelixUtil.PathUniversal(path);

            if (Path.IsPathRooted(path))
            {
                path = RemoveRootFromPath(path, FullName);
            }

            return(HelixUtil.PathNative(Path.Combine(this.FullName, path)));
        }
Esempio n. 4
0
        /// <summary>
        /// Moves or renames the file.
        /// </summary>
        /// <param name="destinationPath">Should be an absolute path or relitive to the root</param>
        public FSFile MoveTo(string destinationPath)
        {
            if (string.IsNullOrEmpty(destinationPath))
            {
                throw new ArgumentNullException(nameof(destinationPath));
            }

            destinationPath = HelixUtil.PathUniversal(destinationPath);

            if (Path.IsPathRooted(destinationPath))
            {
                destinationPath = RemoveRootFromPath(destinationPath, Root.FullName);
            }

            var destinationDirectory = Path.GetDirectoryName(destinationPath);

            if (Root.TryGetEntry(destinationDirectory) as FSDirectory == null)
            {
                throw new System.IO.DirectoryNotFoundException("Could not find a part of the path");
            }

            if ((Root.TryGetEntry(destinationDirectory) as FSDirectory).TryGetEntry(Path.GetFileName(destinationPath)) != null)
            {
                throw new System.IO.DirectoryNotFoundException("Cannot move a file when that file already exists.");
            }

            var newEntry = new FSFile(HelixUtil.JoinUniversal(Root.FullName, destinationPath), Root.TryGetEntry(destinationDirectory) as FSDirectory, WhatIf);

            newEntry.PopulateFromInfo(this.LastWriteTimeUtc, this.Length);

            if (!WhatIf)
            {
                File.Move(HelixUtil.PathNative(this.FullName), HelixUtil.PathNative(Path.Combine(Root.FullName, destinationPath)));
            }

            ((IFSDirectoryCore)Parent).Remove(this);
            ((IFSDirectoryCore)(Root.TryGetEntry(destinationDirectory) as FSDirectory)).Add(newEntry);

            return(newEntry);
        }