private static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("USAGE: ArchiveMaker fileName.tar <fileToAdd.ext> [. more files..]"); return; } using (FileStream archUsTar = File.Create(args[0])) { using (TarWriter legacyTar = new TarWriter(archUsTar)) { for (int i = 1; i < args.Length; ++i) { legacyTar.Write(args[i]); } } } Console.WriteLine("Examine tar file: {0}", args[0]); using (FileStream examiner = File.OpenRead(args[0])) { TarReader tar = new TarReader(examiner); while (tar.MoveNext(true)) { Console.WriteLine("File: {0}, Owner: {1}", tar.FileInfo.FileName, tar.FileInfo.UserName); } } using (FileStream unarchFile = File.OpenRead(args[0])) { TarReader reader = new TarReader(unarchFile); reader.ReadToEnd("out_dir\\data"); } }
public byte[] Create(string maintenanceHtml) { MemoryStream tarGzStream; using (var input = new MemoryStream(Encoding.UTF8.GetBytes(maintenanceHtml), false)) using (tarGzStream = new MemoryStream()) using (var gzStream = new GZipStream(tarGzStream, CompressionMode.Compress)) using (var tarWriter = new TarWriter(gzStream)) { tarWriter.Write(input, input.Length, "App_Offline.htm"); } return tarGzStream.GetBuffer(); }
//================================================================================= // // PRIVATE METHODS // //================================================================================= /// <summary> /// The actual backup logic itself. /// We mount the VHD snapshot, then TAR and copy the contents to a new blob. /// </summary> private void Run() { CloudDrive snapshottedDrive = null; bool mountedSnapshot = false; try { Log("Backup started for " + UriToBackup + "..."); // Set up the cache, storage account, and blob client. Log("Getting the cache..."); var localResource = RoleEnvironment.GetLocalResource(Constants.BackupLocalStorageName); Log("Initializing the cache..."); CloudDrive.InitializeCache(localResource.RootPath, localResource.MaximumSizeInMegabytes); Log("Setting up storage account..."); var storageAccount = CloudStorageAccount.Parse(Credential); var client = storageAccount.CreateCloudBlobClient(); // Mount the snapshot. Log("Mounting the snapshot..."); snapshottedDrive = new CloudDrive(UriToBackup, storageAccount.Credentials); string driveLetter = snapshottedDrive.Mount(0, DriveMountOptions.None); mountedSnapshot = true; Log("...snapshot mounted to " + driveLetter); // Create the destination blob. Log("Opening (or creating) the backup container..."); CloudBlobContainer backupContainer = client.GetContainerReference(BackupContainerName); backupContainer.CreateIfNotExist(); var blobFileName = String.Format(Constants.BackupFormatString, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute); var blob = backupContainer.GetBlobReference(blobFileName); // Write everything in the mounted snapshot, to the TarWriter stream, to the BlobStream, to the blob. Log("Backing up:\n\tpath: " + driveLetter + "\n\tto blob: " + blobFileName + "\n"); using (var outputStream = blob.OpenWrite()) { using (var tar = new TarWriter(outputStream)) { Log("Writing to the blob/tar..."); AddAllToTar(driveLetter, tar); } } // Set the blob's metadata. Log("Setting the blob's metadata..."); blob.Metadata["FileName"] = blobFileName; blob.Metadata["Submitter"] = "BlobBackup"; blob.SetMetadata(); Log("Unmounting the drive..."); // Keep this here because we want "terminating now" to be the last log event in a failure. } catch (Exception e) { Log("========================="); Log("FAILURE: " + e.Message); Log(e.StackTrace); Log(""); Log("Terminating now."); } finally { // Unmount the drive. if (mountedSnapshot) { snapshottedDrive.Unmount(); } DateFinished = DateTime.Now; } }
/// <summary> /// Adds every file in the directory to the tar, and recurses into subdirectories. /// </summary> private void AddAllToTar(string root, TarWriter tar) { Log("Opening in " + root + "..."); // Add subdirectories... foreach (var directory in Directory.GetDirectories(root)) { var dirName = new DirectoryInfo(directory).Name; if (skipDirectories.Contains(dirName.ToUpperInvariant())) { Log("Skipping directory "+directory+" and its subdirectories"); } else { AddAllToTar(directory, tar); } } foreach (var file in Directory.GetFiles(root)) { var info = new FileInfo(file); Log("Writing " + info.Name + "... (" + Util.FormatFileSize(info.Length) + ")"); using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { tar.Write(fs); } } }
public static string BuildOBB() { try { var tmpfoler = "/tmp/packs"; GeneralUtils.DeleteDirectory(tmpfoler, true); // mko: cleaning up build folder Directory.CreateDirectory(tmpfoler); var version = "1.0"; try { var parts = PlayerSettings.bundleVersion.Split('.'); version = parts[0] + "." + parts[1]; } catch { } // moko: changed to do a debug dump of all builder job info first var date = System.DateTime.Now.ToString("dd/MM/yy HH:mm"); string header = "*******************************************************************************\n"; header += "Building to " + tmpfoler + " @" + date; Debug.Log(header); Debug.Log("Build Setting Parameters:\n" + BuildSettings.ToString()); Debug.Log("Environment Setting Parameters:\n" + EnvironmentUtils.GetEnvirnomentDetails()); var cl = EnvironmentUtils.Get("BUILD_CL", "0"); PlayerSettings.bundleVersion = version + "." + cl; // step1 build all the bundles (extended bundles) var options = Bundler.BundleOptions.Force | Bundler.BundleOptions.Extended | Bundler.BundleOptions.SkipBase; var packs = Bundler.BuildAll(BuildSettings.BundlerConfigFolder, options); var tarPath = Path.Combine(tmpfoler, "packs.tar"); var packPath = BuildSettings.BuildFolder; var gzipPath = tarPath + ".gz"; var filesPath = Path.Combine(packPath, "files.json"); FileUtil.DeleteFileOrDirectory(filesPath); // calculate the files var files = new Hashtable(); foreach (var packFile in Directory.GetFiles(packPath, "*", SearchOption.AllDirectories)) { var relativeName = packFile.Substring(packPath.Length + 1); var finfo = new FileInfo(packFile); files[relativeName] = finfo.Length; } // write to the files.json var fileData = new Hashtable(); fileData["packs"] = packs; fileData["files"] = files; File.WriteAllBytes(filesPath, EB.Encoding.GetBytes(EB.JSON.Stringify(fileData))); // turn into gz, tar archive using (var gzFile = new FileStream(gzipPath, FileMode.Create, FileAccess.ReadWrite)) { using (var gzStream = new Ionic.Zlib.GZipStream(gzFile, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression)) { var writer = new tar_cs.TarWriter(gzStream); foreach (var packFile in Directory.GetFiles(packPath, "*", SearchOption.AllDirectories)) { var relativeName = packFile.Substring(packPath.Length + 1); //Debug.Log("file: " + relativeName); using (var f = new FileStream(packFile, FileMode.Open, FileAccess.Read)) { writer.Write(f, f.Length, relativeName, string.Empty, string.Empty, 511, System.DateTime.UtcNow); } } writer.Close(); } } //var url = S3Utils.Put(gzipPath, Path.Combine(cl,cl+".obb") ); //return url; return(gzipPath); } catch (System.Exception ex) { Debug.Log("BuildOBB Failed: exception: " + ex.ToString()); throw ex; } }
/// <summary> /// Adds every file in the directory to the tar, and recurses into subdirectories. /// </summary> private void AddAllToTar(string root, TarWriter tar) { Log("Opening in " + root + "..."); // Add subdirectories... foreach (var directory in Directory.GetDirectories(root)) { AddAllToTar(directory, tar); } foreach (var file in Directory.GetFiles(root)) { var info = new FileInfo(file); Log("Writing " + info.Name + "... (" + Util.FormatFileSize(info.Length) + ")"); using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { tar.Write(fs); } } }
public static void BuildContentPacksWithOptions(string distList, bool skipBase, bool uploadProduction = false) { try { var tmpfoler = "/tmp/packs"; GeneralUtils.DeleteDirectory(tmpfoler, true); // mko: cleaning up build folder Directory.CreateDirectory(tmpfoler); var version = "1.0"; try { var parts = PlayerSettings.bundleVersion.Split('.'); version = parts[0] + "." + parts[1]; } catch { } var platform = BuildSettings.Target; var date = System.DateTime.Now.ToString("dd/MM/yy HH:mm"); var cl = EnvironmentUtils.Get("BUILD_CL", "0"); var desc = "Content Package " + BuildSettings.Target + " " + date + " CL: " + cl + "\n"; var notes = (ArrayList)EB.JSON.Parse(EnvironmentUtils.Get("BUILD_NOTES", "[]")); PlayerSettings.bundleVersion = version + "." + cl; // step1 build all the bundles (extended bundles) var options = Bundler.BundleOptions.Force | Bundler.BundleOptions.Extended; if (skipBase) { options |= Bundler.BundleOptions.SkipBase; } var packs = Bundler.BuildAll(BuildSettings.BundlerConfigFolder, options); var files = new ArrayList(); foreach (var pack in packs) { var tarPath = Path.Combine(tmpfoler, pack + ".tar"); var packPath = Path.Combine(BuildSettings.BuildFolder, pack); var gzipPath = tarPath + ".gz"; // turn into gz, tar archive using (var gzFile = new FileStream(gzipPath, FileMode.Create, FileAccess.ReadWrite)) { using (var gzStream = new Ionic.Zlib.GZipStream(gzFile, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression)) { var writer = new tar_cs.TarWriter(gzStream); foreach (var packFile in Directory.GetFiles(packPath, "*", SearchOption.AllDirectories)) { var relativeName = packFile.Substring(packPath.Length + 1); //Debug.Log("file: " + relativeName); using (var f = new FileStream(packFile, FileMode.Open, FileAccess.Read)) { writer.Write(f, f.Length, relativeName, string.Empty, string.Empty, 511, System.DateTime.UtcNow); } } writer.Close(); } } var info = new Hashtable(); var size = new FileInfo(gzipPath).Length; info["size"] = size; info["url"] = S3Utils.Put(gzipPath, Path.Combine(cl, Path.GetFileName(gzipPath))); info["md5"] = S3Utils.CalculateMD5(gzipPath); info["pack"] = pack; info["included"] = skipBase; files.Add(info); } // send email var data = new Hashtable(); data["cl"] = int.Parse(cl); data["minVersion"] = int.Parse(cl); data["title"] = desc; data["notes"] = notes; data["files"] = files; data["platform"] = platform; var manifest = EB.JSON.Stringify(data); var manifestUrl = S3Utils.PutData(EB.Encoding.GetBytes(manifest), "manifest.json", Path.Combine(cl, "manifest.json")); data["manifest"] = manifestUrl; if (!string.IsNullOrEmpty(manifestUrl)) { UploadContentManifest(WWWUtils.Environment.LocalTest, manifestUrl, skipBase ? 1 : 0); if (uploadProduction) { UploadContentManifest(WWWUtils.Environment.LocalTest, manifestUrl, skipBase ? 1 : 0); } } Email(distList, "New " + platform + " Content Build: " + cl, File.ReadAllText("Assets/Editor/EB.Core.Editor/Build/Email/contentbuild.txt"), data); Done(); } catch (System.Exception ex) { Debug.Log("BuildContentPacks Failed: exception: " + ex.ToString()); Failed(ex); } ClearProgressBar(); }