Exemplo n.º 1
0
        /// <summary>
        /// Extracts the target logset.
        /// </summary>
        /// <returns>The root path where files were extracted.</returns>
        public ExtractionResult Extract(string target, string destination)
        {
            // Unpack files.
            try
            {
                using (var unpackTimer = new LogsharkTimer("Unpack Archives", GlobalEventTimingData.Add))
                {
                    ICollection <string> archivesToUnpack = GetArchivesToUnpack(target, destination);
                    var unpackResults = UnpackArchives(archivesToUnpack, destination, PathHelper.IsDirectory(target));

                    if (unpackResults.Any())
                    {
                        long inputSize     = DiskSpaceHelper.GetSize(target);
                        long extractedSize = DiskSpaceHelper.GetDirectorySize(destination);
                        Log.InfoFormat("Finished extracting required files from logset! Unpacked {0} out of {1}. [{2}]", extractedSize.ToPrettySize(), inputSize.ToPrettySize(), unpackTimer.Elapsed.Print());
                    }

                    return(new ExtractionResult(destination, unpackResults));
                }
            }
            catch (ZipException ex)
            {
                throw new InvalidLogsetException(String.Format("Cannot read logset archive: {0}", ex.Message));
            }
            catch (InsufficientDiskSpaceException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ExtractionException(ex.Message, ex);
            }
        }
Exemplo n.º 2
0
        protected long GetRequiredDiskSpace(string target)
        {
            if (PathHelper.IsDirectory(target))
            {
                return(GetWhitelistedFilesInDirectory(target).Sum(file => DiskSpaceHelper.GetSize(file)));
            }

            return(DiskSpaceHelper.GetSize(target));
        }
Exemplo n.º 3
0
        private static void ValidateSufficientDiskSpaceToCopyTargetLocally(LogsharkRequest request, ISet<Regex> whitelistPatterns)
        {
            long availableDiskSpace = DiskSpaceHelper.GetAvailableFreeSpace(GetUnpackTempDirectory());

            long requiredDiskSpace = 0;
            if (request.Target.IsDirectory)
            {
                foreach (string requiredFile in GetRequiredFilesInDirectory(request, whitelistPatterns))
                {
                    requiredDiskSpace += DiskSpaceHelper.GetSize(requiredFile);
                }
            }
            else if (request.Target.IsFile)
            {
                requiredDiskSpace = DiskSpaceHelper.GetSize(request.Target);
            }

            if (requiredDiskSpace > availableDiskSpace)
            {
                throw new InsufficientDiskSpaceException(String.Format("Failed to copy target '{0}' to local temp directory: Not enough free disk space available! ({1} available, {2} required)",
                                                                        request.Target, availableDiskSpace.ToPrettySize(), requiredDiskSpace.ToPrettySize()));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Extracts a target archive to a target directory.
        /// </summary>
        /// <param name="archive">The path to the archive.</param>
        /// <param name="destinationDirectory">The directory to extract the archive to.</param>
        /// <param name="deleteOnFinish">Indicates whether this archive should be deleted after unzipping it.</param>
        public UnzipResult Unzip(string archive, string destinationDirectory, bool deleteOnFinish = false)
        {
            // Validate archive exists.
            if (!File.Exists(archive))
            {
                throw new ArgumentException(String.Format("Archive '{0}' does not exist!", archive));
            }

            Directory.CreateDirectory(destinationDirectory);
            ValidateSufficientDiskSpaceToUnpack(archive, destinationDirectory);

            Log.InfoFormat("Extracting contents of archive '{0}' to '{1}'.. ({2})", Path.GetFileName(archive), destinationDirectory, DiskSpaceHelper.GetSize(archive).ToPrettySize(decimalPlaces: 1));
            return(ExtractArchive(archive, destinationDirectory, deleteOnFinish));
        }