Пример #1
0
        public void ZipValid_ContainsFilenameWithBadChars_NoException()
        {
            // We want to inspect a localized error message below.
            // Switch to English to ensure it's what we expect.
            CultureInfo origUICulture = Thread.CurrentThread.CurrentUICulture;

            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            bool   valid  = false;
            string reason = "";

            Assert.DoesNotThrow(() =>
                                valid = NetFileCache.ZipValid(TestData.ZipWithBadChars, out reason));

            // The file is considered valid on Linux;
            // only check the reason if found invalid
            if (!valid)
            {
                Assert.AreEqual(
                    @"Error in step EntryHeader for GameData/FlagPack/Flags/Weyland-Yutani from ""Alien"".png: Exception during test - 'Name is invalid'",
                    reason
                    );
            }

            // Switch back to the original locale
            Thread.CurrentThread.CurrentUICulture = origUICulture;
        }
Пример #2
0
        public void ZipValid_ContainsFilenameWithUnicodeChars_Valid()
        {
            bool   valid  = false;
            string reason = null;

            Assert.DoesNotThrow(() =>
                                valid = NetFileCache.ZipValid(TestData.ZipWithUnicodeChars, out reason));
            Assert.IsTrue(valid, reason);
        }
Пример #3
0
        public string DownloadPackage(Uri url, string identifier, DateTime?updated)
        {
            _requestedURLs.Add(url);

            var cachedFile = _cache.GetCachedFilename(url, updated);

            if (!string.IsNullOrWhiteSpace(cachedFile))
            {
                return(cachedFile);
            }
            else
            {
                var downloadedFile = Net.Download(url);

                string extension;

                switch (FileIdentifier.IdentifyFile(downloadedFile))
                {
                case FileType.ASCII:
                    extension = "txt";
                    break;

                case FileType.GZip:
                    extension = "gz";
                    break;

                case FileType.Tar:
                    extension = "tar";
                    break;

                case FileType.TarGz:
                    extension = "tar.gz";
                    break;

                case FileType.Zip:
                    extension = "zip";
                    string invalidReason;
                    if (!NetFileCache.ZipValid(downloadedFile, out invalidReason))
                    {
                        throw new Kraken($"{downloadedFile} is not a valid ZIP file: {invalidReason}");
                    }
                    break;

                default:
                    extension = "ckan-package";
                    break;
                }

                return(_cache.Store(
                           url,
                           downloadedFile,
                           string.Format("netkan-{0}.{1}", identifier, extension),
                           move: true
                           ));
            }
        }
Пример #4
0
        public void ZipValid_ContainsFilenameWithBadChars_NoException()
        {
            bool   valid  = false;
            string reason = "";

            Assert.DoesNotThrow(() =>
                                valid = NetFileCache.ZipValid(TestData.ZipWithBadChars, out reason));

            // The file is considered valid on Linux;
            // only check the reason if found invalid
            if (!valid)
            {
                Assert.AreEqual(reason, "Illegal characters in path.");
            }
        }
Пример #5
0
        public void ZipValid_ContainsFilenameWithBadChars_NoException()
        {
            // We want to inspect a localized error message below.
            // Switch to English to ensure it's what we expect.
            CultureInfo origUICulture = Thread.CurrentThread.CurrentUICulture;

            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            bool   valid  = false;
            string reason = "";

            Assert.DoesNotThrow(() =>
                                valid = NetFileCache.ZipValid(TestData.ZipWithBadChars, out reason));

            // The file is considered valid on Linux;
            // only check the reason if found invalid
            if (!valid)
            {
                Assert.AreEqual(reason, "Illegal characters in path.");
            }

            // Switch back to the original locale
            Thread.CurrentThread.CurrentUICulture = origUICulture;
        }
Пример #6
0
        private string DownloadPackage(Uri url, string identifier, DateTime?updated, Uri primaryUrl = null)
        {
            if (primaryUrl == null)
            {
                primaryUrl = url;
            }
            if (_overwriteCache && !_requestedURLs.Contains(url))
            {
                // Discard cached file if command line says so,
                // but only the first time in each run
                _cache.Remove(url);
            }

            _requestedURLs.Add(url);

            var cachedFile = _cache.GetCachedFilename(primaryUrl, updated);

            if (!string.IsNullOrWhiteSpace(cachedFile))
            {
                return(cachedFile);
            }
            else
            {
                var downloadedFile = Net.Download(url);

                string extension;

                switch (FileIdentifier.IdentifyFile(downloadedFile))
                {
                case FileType.ASCII:
                    extension = "txt";
                    break;

                case FileType.GZip:
                    extension = "gz";
                    break;

                case FileType.Tar:
                    extension = "tar";
                    break;

                case FileType.TarGz:
                    extension = "tar.gz";
                    break;

                case FileType.Zip:
                    extension = "zip";
                    string invalidReason;
                    if (!NetFileCache.ZipValid(downloadedFile, out invalidReason))
                    {
                        log.Debug($"{downloadedFile} is not a valid ZIP file: {invalidReason}");
                        throw new Kraken($"{url} is not a valid ZIP file: {invalidReason}");
                    }
                    break;

                default:
                    extension = "ckan-package";
                    break;
                }

                return(_cache.Store(
                           primaryUrl,
                           downloadedFile,
                           string.Format("netkan-{0}.{1}", identifier, extension),
                           move: true
                           ));
            }
        }