Ejemplo n.º 1
0
        // Generates a tarball including all the requested entries
        // @return tarball path
        public string GenerateTarball()
        {
            string tmpDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            try
            {
                // TODO: check if space left?
                Directory.CreateDirectory(tmpDir);

                string outDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
                Directory.CreateDirectory(outDir);

                this.UsedDirectories.Add(outDir);

                CopyFiles(tmpDir);

                string tarballPath = Path.Combine(outDir, "files.tgz");

                FileArchive.ZipFile(tmpDir, tarballPath);

                return(tarballPath);
            }
            finally
            {
                if (!string.IsNullOrEmpty(tmpDir) && Directory.Exists(tmpDir))
                {
                    Directory.Delete(tmpDir, true);
                }
            }
        }
Ejemplo n.º 2
0
        internal static void UnpackBlob(string blobstoreId, string checksum, string installPath)
        {
            Logger.Info("Retrieving blob: {0}", blobstoreId);

            IClient blobstoreClient = Blobstore.CreateClient(Config.BlobstoreProvider, Config.BlobstoreOptions);

            FileInfo fileInfo = new FileInfo(Path.Combine(Config.BaseDir, "data", "tmp", blobstoreId + ".tgz"));

            try
            {
                if (!Directory.Exists(fileInfo.Directory.ToString()))
                {
                    Directory.CreateDirectory(fileInfo.Directory.ToString());
                }

                blobstoreClient.Get(blobstoreId, fileInfo);

                string blobDataFile = fileInfo.FullName;

                Logger.Info("Done retrieving blob");

                if (!Directory.Exists(installPath))
                {
                    Logger.Info("Creating ", installPath);
                    Directory.CreateDirectory(installPath);
                }

                string blobSHA1;
                using (FileStream fs = fileInfo.Open(FileMode.Open))
                {
                    using (SHA1 sha = new SHA1CryptoServiceProvider())
                    {
                        blobSHA1 = BitConverter.ToString(sha.ComputeHash(fs)).Replace("-", "");
                    }
                }
                if (String.Compare(blobSHA1, checksum, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new MessageHandlerException(String.Format(CultureInfo.InvariantCulture, "Expected sha1: {0}, Downloaded sha1: {1}", checksum, blobSHA1));
                }

                Logger.Debug("Extracting {0}", blobDataFile);
                FileArchive.UnzipFile(installPath, blobDataFile);
                Logger.Debug("Done extracting {0}", blobDataFile);
                File.Delete(fileInfo.FullName);
            }
            catch (Exception ex)
            {
                Logger.Error("Failure unpacking blob.", ex.ToString());
                throw;
            }
        }
Ejemplo n.º 3
0
 internal static void PackBlob(string directory, string fileName)
 {
     FileArchive.ZipFile(directory, fileName);
 }