You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/03/03 03:36:16 UTC

[lucy-commits] svn commit: r1076504 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Util.pm src/CFCUtil.c src/CFCUtil.h

Author: marvin
Date: Thu Mar  3 02:36:16 2011
New Revision: 1076504

URL: http://svn.apache.org/viewvc?rev=1076504&view=rev
Log:
Finish porting CFCUtil to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Util.pm
    incubator/lucy/trunk/clownfish/src/CFCUtil.c
    incubator/lucy/trunk/clownfish/src/CFCUtil.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1076504&r1=1076503&r2=1076504&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Mar  3 02:36:16 2011
@@ -1546,6 +1546,14 @@ CODE:
     FREEMEM(contents);
 OUTPUT: RETVAL
 
+int
+current(orig, dest)
+    const char *orig;
+    const char *dest;
+CODE:
+    RETVAL = CFCUtil_current(orig, dest);
+OUTPUT: RETVAL
+
 void
 write_if_changed(path, content_sv)
     const char *path;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Util.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Util.pm?rev=1076504&r1=1076503&r2=1076504&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Util.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Util.pm Thu Mar  3 02:36:16 2011
@@ -33,34 +33,6 @@ our @EXPORT_OK = qw(
     trim_whitespace
 );
 
-sub current {
-    my ( $orig, $dest ) = @_;
-    my $bubble_time = time;
-    $orig = [$orig] unless ref($orig) eq 'ARRAY';
-    $dest = [$dest] unless ref($dest) eq 'ARRAY';
-
-    # If a destination file doesn't exist, we're not current.
-    for (@$dest) {
-        return 0 unless -e $_;
-    }
-
-    # Find the oldest file from the destination group.
-    for (@$dest) {
-        my $candidate = ( stat($_) )[9];
-        $bubble_time = $candidate if $candidate < $bubble_time;
-    }
-
-    # If any source file is newer than the oldest dest, we're not current.
-    for (@$orig) {
-        confess "Missing source file '$_'" unless -e $_;
-        my $candidate = ( stat($_) )[9];
-        return 0 if $candidate > $bubble_time;
-    }
-
-    # Current!
-    return 1;
-}
-
 sub verify_args {
     my $defaults = shift;    # leave the rest of @_ intact
 

Modified: incubator/lucy/trunk/clownfish/src/CFCUtil.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCUtil.c?rev=1076504&r1=1076503&r2=1076504&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCUtil.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCUtil.c Thu Mar  3 02:36:16 2011
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <errno.h>
+#include <sys/stat.h>
 
 #ifndef true
     #define true 1
@@ -136,6 +137,28 @@ CFCUtil_wrapped_free(void *ptr)
     free(ptr);
 }
 
+int
+CFCUtil_current(const char *orig, const char *dest)
+{
+    // If the destination file doesn't exist, we're not current.
+    struct stat dest_stat;
+    if (stat(dest, &dest_stat) == -1) { 
+        return false;
+    }   
+
+    // If the source file is newer than the dest, we're not current.
+    struct stat orig_stat;
+    if (stat(orig, &orig_stat) == -1) { 
+        Util_die("Missing source file '%s'", orig);
+    }
+    if (orig_stat.st_mtime > dest_stat.st_mtime) {
+        return false;
+    }
+
+    // Current!
+    return 1;
+}
+
 void
 CFCUtil_write_file(const char *filename, const char *content, size_t len)
 {

Modified: incubator/lucy/trunk/clownfish/src/CFCUtil.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCUtil.h?rev=1076504&r1=1076503&r2=1076504&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCUtil.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCUtil.h Thu Mar  3 02:36:16 2011
@@ -83,6 +83,9 @@ CFCUtil_wrapped_free(void *ptr);
 #define FREEMEM(_ptr) \
     CFCUtil_wrapped_free(_ptr)
 
+int
+CFCUtil_current(const char *orig, const char *dest);
+
 /* Open a file (truncating if necessary) and write [content] to it.  CFCUtil_die() if
  * an error occurs.
  */