Permalink
Browse files

Add a Cache object

  • Loading branch information...
hbons committed Sep 10, 2011
1 parent 0b3f6ac commit 83521b4f49f1f93ed2eb08729c736a55bf74174d
Showing with 102 additions and 5 deletions.
  1. +59 −0 Rainbows/Cache.cs
  2. +25 −1 Rainbows/Index.cs
  3. +7 −0 Rainbows/Main.cs
  4. +10 −4 Rainbows/Objects.cs
  5. +1 −0 Rainbows/Rainbows.csproj
View
@@ -0,0 +1,59 @@
+// Rainbows, an experimental backend for SparkleShare
+// Copyright (C) 2011 Hylke Bons <hylkebons@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+using System;
+using System.IO;
+
+namespace Rainbows {
+
+ public class Cache {
+
+ public string [] Missing;
+ public string [] Modified;
+ public string [] New;
+
+
+ public Cache (string cache_file_path)
+ {
+ }
+
+
+ public void Update ()
+ {
+ }
+
+
+ public string [] CompareDirectory (string path)
+ {
+ return new string [0]; // TODO return all touched, new, and missing paths
+ }
+
+
+ public static void Create (string cache_file_path)
+ {
+ string parent_path = Path.GetDirectoryName (cache_file_path);
+
+ if (File.Exists (cache_file_path))
+ File.Delete (cache_file_path);
+
+ if (!Directory.Exists (parent_path))
+ Directory.CreateDirectory (parent_path);
+
+ File.Create (cache_file_path);
+ }
+ }
+}
View
@@ -59,7 +59,7 @@ public Index (string database_path, string checkout_path, User user)
public void Status ()
{
- // TODO compare the checkout with the HEAD tree
+ // TODO compare the checkout with the cache
}
@@ -87,9 +87,31 @@ public void Commit ()
// remove hash to "todo" transfer list
};
+
+ //chunker.Finished += delegate (Chunk [] chunks) {
+ // Blob blob = Blob.Write (chunks);
+ //};
+
// TODO: needs to block
+
+
chunker.FileToChunks ("/Users/hbons/hp2.avi", 4 * 1024 * 1024);
+ User author = new User { Name = "Hylke Bons", Email = "hylkebons@gmail.com" };
+
+
+
+
+
+
+
+
+
+
+
+
+ Objects.Commit.Write (author, DateTime.UtcNow, Head, null);
+
// TODO: Walk the new tree and create blobs, trees, commit
//
// foreach
@@ -122,6 +144,8 @@ public void Checkout (string commit_hash)
// TODO: walk the HEAD tree
//chunker.ChunksToFile (chunks, path);
+
+ // TODO: write cache
}
View
@@ -30,6 +30,13 @@ public class Rainbows {
public static void Main (string [] args)
{
+
+ Console.WriteLine (File.GetLastWriteTimeUtc ("/home/hbons/test.txt").GetHashCode ());
+ Environment.Exit (0);
+
+
+
+
User user = new User {
Name = "Hylke Bons",
Email = "hylkebons@gmail.com"
View
@@ -28,13 +28,14 @@ public abstract class HashObject {
public static string DatabasePath;
public string Hash;
+
public HashObject (string hash)
{
Hash = hash;
}
- protected byte [] ReadHashObject (string hash)
+ protected static byte [] ReadHashObject (string hash)
{
string file_path = Path.Combine (DatabasePath, "objects",
hash.Substring (0, 2), hash.Substring (2));
@@ -51,8 +52,13 @@ public HashObject (string hash)
public static void WriteHashObject (string hash, byte [] buffer)
{
- string file_path = Path.Combine (DatabasePath, "objects",
- hash.Substring (0, 2), hash.Substring (2));
+ string container_path = Path.Combine (DatabasePath, "objects",
+ hash.Substring (0, 2));
+
+ string file_path = Path.Combine (container_path, hash.Substring (2));
+
+ if (!Directory.Exists (container_path))
+ Directory.CreateDirectory (container_path);
try {
File.WriteAllBytes (file_path, buffer);
@@ -106,7 +112,7 @@ public Commit (string hash) : base (hash)
{
int seconds_since_epoch = (int) (timestamp - new DateTime (1970, 1, 1)).TotalSeconds;
- string line = root.Hash + " " + seconds_since_epoch + " " +
+ string line = root.Hash + " " + parent.Hash + " " + seconds_since_epoch + " " +
author.Name + " " + "<" + author.Email + ">" + "\n";
string hash = Utils.SHA1 (line);
View
@@ -45,6 +45,7 @@
<Compile Include="ConnectionData.cs" />
<Compile Include="User.cs" />
<Compile Include="Exceptions.cs" />
+ <Compile Include="Cache.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />

0 comments on commit 83521b4

Please sign in to comment.