public void NameTransforms()
        {
            INameTransform t = new ZipNameTransform(@"C:\Slippery");

            Assert.AreEqual("Pongo/Directory/", t.TransformDirectory(@"C:\Slippery\Pongo\Directory"), "Value should be trimmed and converted");
            Assert.AreEqual("PoNgo/Directory/", t.TransformDirectory(@"c:\slipperY\PoNgo\Directory"), "Trimming should be case insensitive");
            Assert.AreEqual("slippery/Pongo/Directory/", t.TransformDirectory(@"d:\slippery\Pongo\Directory"), "Trimming should be case insensitive");

            Assert.AreEqual("Pongo/File", t.TransformFile(@"C:\Slippery\Pongo\File"), "Value should be trimmed and converted");
        }
        public void NameTransforms_Posix()
        {
            INameTransform t = new ZipNameTransform(@"/Slippery");

            Assert.AreEqual("Pongo/Directory/", t.TransformDirectory(@"/Slippery\Pongo\Directory"), "Value should be trimmed and converted");
            Assert.AreEqual("PoNgo/Directory/", t.TransformDirectory(@"/slipperY\PoNgo\Directory"), "Trimming should be case insensitive");
            Assert.AreEqual("slippery/Pongo/Directory/", t.TransformDirectory(@"/slippery/slippery/Pongo/Directory"), "Trimming should account for root");

            Assert.AreEqual("Pongo/File", t.TransformFile(@"/Slippery/Pongo/File"), "Value should be trimmed and converted");
        }
        public void LengthBoundaryOk()
        {
            var zt = new ZipNameTransform();
            var tooLongWithRoot = Utils.SystemRoot + new string('x', 65535);

            Assert.DoesNotThrow(() => zt.TransformDirectory(tooLongWithRoot));
        }
        public void TooLong()
        {
            var zt      = new ZipNameTransform();
            var tooLong = new string('x', 65536);

            Assert.Throws <PathTooLongException>(() => zt.TransformDirectory(tooLong));
        }
 public override void CreateDirectory(string directory)
 {
     if (this.IsOpen)
     {
         directory = _zipNameTransform.TransformDirectory(directory);
         System.Diagnostics.Trace.WriteLine("Adding directory: " + directory);
         ZipEntry entry = new ZipEntry(directory);
         _zipOutput.PutNextEntry(entry);
     }
 }
        public void LengthBoundaryOk()
        {
            var    zt       = new ZipNameTransform();
            string veryLong = "c:\\" + new string('x', 65535);

            try {
                zt.TransformDirectory(veryLong);
            } catch {
                Assert.Fail("Expected no exception");
            }
        }
        public void TooLong()
        {
            var zt       = new ZipNameTransform();
            var veryLong = new string('x', 65536);

            try {
                zt.TransformDirectory(veryLong);
                Assert.Fail("Expected an exception");
            } catch (PathTooLongException) {
            }
        }
Example #8
0
        public override IAsyncOperation <BaseStorageFolder> CreateFolderAsync(string desiredName, CreationCollisionOption options)
        {
            return(AsyncInfo.Run <BaseStorageFolder>(async(cancellationToken) =>
            {
                using (ZipFile zipFile = await OpenZipFileAsync(FileAccessMode.ReadWrite))
                {
                    if (zipFile == null)
                    {
                        return null;
                    }
                    zipFile.IsStreamOwner = true;

                    var znt = new ZipNameTransform(ContainerPath);
                    var zipDesiredName = znt.TransformDirectory(System.IO.Path.Combine(Path, desiredName));
                    var entry = zipFile.GetEntry(zipDesiredName);

                    zipFile.BeginUpdate(new MemoryArchiveStorage(FileUpdateMode.Direct));
                    if (entry != null)
                    {
                        if (options != CreationCollisionOption.ReplaceExisting)
                        {
                            zipFile.AbortUpdate();
                            return null;
                        }
                        zipFile.Delete(entry);
                    }
                    zipFile.AddDirectory(zipDesiredName);
                    zipFile.CommitUpdate();

                    var wnt = new WindowsNameTransform(ContainerPath);
                    return new ZipStorageFolder(wnt.TransformFile(zipDesiredName), ContainerPath)
                    {
                        ZipEncoding = ZipEncoding,
                        BackingFile = BackingFile
                    };
                }
            }));
        }