about summary refs log tree commit diff
path: root/src/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-05-25T22·42+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-05-25T22·42+0000
commit7dd91d3779b4f806ac0085e0ccc60416d81c1148 (patch)
treee4c5f7e8d8978df671050fae0c25639cca79e251 /src/util.hh
parent0ef4b6d0f8dcaec093e3db366b6dfb6ba47f73a6 (diff)
* Prebuilt package sharing. We allow transparent binary deployment by
  sharing package directories (i.e., the result of building a Nix
  descriptor).

  `nix-pull-prebuilts' obtains a list of all known prebuilts by
  consulting the paths and URLs specified in
  $prefix/etc/nix/prebuilts.conf.  The mappings ($pkghash,
  $prebuilthash) and ($prebuilthash, $location) are registered with
  Nix so that it can use the prebuilt with hash $prebuilthash when
  installing a package with hash $pkghash by downloading and unpacking
  $location.

  `nix-push-prebuilts' creates prebuilts for all packages for which no
  prebuilt is known to exist.  It can then optionally upload these
  to the network through rsync.

  `nix-[pull|push]-prebuilts' just provide a policy.  Nix provides the
  mechanism through the `nix [export|regprebuilt|regurl]' commands.


Diffstat (limited to 'src/util.hh')
-rw-r--r--src/util.hh36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/util.hh b/src/util.hh
index fb405b0f1200..9b3f212de359 100644
--- a/src/util.hh
+++ b/src/util.hh
@@ -85,17 +85,22 @@ string printHash(unsigned char * buf)
 
     
 /* Verify that a reference is valid (that is, is a MD5 hash code). */
-void checkHash(const string & s)
+bool isHash(const string & s)
 {
-    string err = "invalid reference: " + s;
-    if (s.length() != 32)
-        throw BadRefError(err);
+    if (s.length() != 32) return false;
     for (int i = 0; i < 32; i++) {
         char c = s[i];
         if (!((c >= '0' && c <= '9') ||
               (c >= 'a' && c <= 'f')))
-            throw BadRefError(err);
+            return false;
     }
+    return true;
+}
+
+
+void checkHash(const string & s)
+{
+    if (!isHash(s)) throw BadRefError("invalid reference: " + s);
 }
 
 
@@ -113,4 +118,25 @@ string hashFile(string filename)
 }
 
 
+
+/* Return the directory part of the given path, i.e., everything
+   before the final `/'. */
+string dirOf(string s)
+{
+    unsigned int pos = s.rfind('/');
+    if (pos == string::npos) throw Error("invalid file name");
+    return string(s, 0, pos);
+}
+
+
+/* Return the base name of the given path, i.e., everything following
+   the final `/'. */
+string baseNameOf(string s)
+{
+    unsigned int pos = s.rfind('/');
+    if (pos == string::npos) throw Error("invalid file name");
+    return string(s, pos + 1);
+}
+
+
 #endif /* !__UTIL_H */