Permalink
Browse files

Use rsync to sync the database

  • Loading branch information...
1 parent f9340f6 commit 462f479fb1c1a7e4729cf932203205efe0d3253e @hbons committed Jul 31, 2011
Showing with 56 additions and 11 deletions.
  1. +16 −8 Chunker.cs
  2. +8 −2 Main.cs
  3. +2 −0 Repository.cs
  4. +30 −1 TransferManager.cs
View
@@ -66,23 +66,31 @@ public void FileToChunks (string source_file_path)
while ((current_chunk_size = stream.Read (buffer, 0, buffer.Length)) > 0)
{
string hash = Cryptographer.SHA1 (buffer);
- string chunk_file_name = hash;
- string chunk_container = chunk_file_name.Substring (6, 2);
+ string chunk_file_name = hash.Substring (2);
+ string chunk_container = hash.Substring (0, 2);
string chunk_container_path = Path.Combine (OutputDirectory, chunk_container);
string chunk_file_path = Path.Combine (chunk_container_path, chunk_file_name);
if (!File.Exists (chunk_file_path)) {
if (!Directory.Exists (chunk_container_path))
Directory.CreateDirectory (chunk_container_path);
- if (this.cryptographer != null)
- buffer = this.cryptographer.Encrypt (buffer);
+ if (this.cryptographer != null) {
+ byte [] crypto_buffer = this.cryptographer.Encrypt (buffer);
+ File.WriteAllBytes (chunk_file_path, crypto_buffer);
- File.WriteAllBytes (chunk_file_path, buffer);
- }
+ } else {
+ File.WriteAllBytes (chunk_file_path, buffer);
+ }
+
+ if (ChunkCreated != null)
+ ChunkCreated (chunk_file_path, current_chunk_size, hash);
- if (ChunkCreated != null)
- ChunkCreated (chunk_file_path, current_chunk_size, hash);
+ Console.WriteLine ("Chunk " + hash + " created");
+
+ } else {
+ Console.WriteLine ("Chunk " + hash + " exists");
+ }
chunk_number++;
}
View
10 Main.cs
@@ -26,6 +26,9 @@ namespace Rainbows
{
public class Rainbows
{
+ public static string RemoteUrl = "ssh://localhost:/Users/hbons/TestTest";
+ public static string LocalPath = "/Users/hbons/SparkleShare/Rainbows/.sparkleshare";
+
public static void Main (string [] args)
{
//
@@ -42,17 +45,20 @@ public static void Main (string [] args)
List<string> hashes = new List<string> ();
chunker.ChunkCreated += delegate (string chunk_file_path, int chunk_size, string chunk_hash) {
- Console.WriteLine ("Created: " + chunk_file_path + " (" + chunk_size + " bytes)");
+ // Console.WriteLine ("Created: " + chunk_file_path + " (" + chunk_size + " bytes)");
chunk_paths.Add (chunk_file_path);
hashes.Add (chunk_hash);
// Upload files
};
- chunker.FileToChunks ("/Users/hbons/SparkleShare/Rainbows/hp.avi");
+ chunker.FileToChunks ("/Users/hbons/Thunderbird.dmg");
Blobs blobs = new Blobs ("Users/hbons/SparkleShare/Rainbows/.sparkleshare");
blobs.Store ("hp.avi", hashes.ToArray ());
+ TransferManager transfer_manager = new TransferManager (LocalPath + "/", "/Users/hbons/rsync-test");
+ transfer_manager.UploadObjects ();
+
s.Stop ();
Console.WriteLine ("Total time: " + (int) s.Elapsed.TotalSeconds + " seconds");
}
View
@@ -16,7 +16,9 @@
using System;
+using System.IO;
using System.Collections;
+using System.Text;
namespace Rainbows {
View
@@ -16,12 +16,41 @@
using System;
+using System.Diagnostics;
namespace Rainbows {
public class TransferManager {
- public TransferManager (string path)
+ Process rsync_process = new Process ();
+
+
+ public TransferManager (string path, string remote_path)
+ {
+ this.rsync_process.StartInfo.FileName = "rsync";
+ this.rsync_process.StartInfo.Arguments = "--ignore-existing " +
+ "--recursive " +
+ "--whole-file " + // Don't do delta sync
+ "--progress " +
+ path + " " + remote_path;
+
+ this.rsync_process.EnableRaisingEvents = true;
+
+ this.rsync_process.StartInfo.RedirectStandardOutput = false;
+ this.rsync_process.StartInfo.UseShellExecute = false;
+ this.rsync_process.StartInfo.WorkingDirectory = path;
+ }
+
+
+ public void UploadObjects ()
+ {
+ Console.WriteLine (this.rsync_process.StartInfo.Arguments);
+ this.rsync_process.Start ();
+ this.rsync_process.WaitForExit ();
+ }
+
+
+ public void DownloadObjects (string [] hashes)
{
}

0 comments on commit 462f479

Please sign in to comment.