Update BSD::stat to 1.33 which gives us the new functions utimes()

and lutimes().  Unfortunately lutimes() is specific to FreeBSD.
Emulate it with OpenBSD utimensat() and add a test for that.
OK sthen@
This commit is contained in:
bluhm 2012-10-21 23:07:12 +00:00
parent 7056f21575
commit e7e6d287ec
4 changed files with 68 additions and 9 deletions

View File

@ -1,11 +1,10 @@
# $OpenBSD: Makefile,v 1.12 2012/08/30 21:16:14 bluhm Exp $
# $OpenBSD: Makefile,v 1.13 2012/10/21 23:07:12 bluhm Exp $
SHARED_ONLY = Yes
COMMENT = stat() with BSD 4.4 extentions
DISTNAME = BSD-stat-1.21
REVISION = 5
DISTNAME = BSD-stat-1.33
CATEGORIES = devel
@ -14,7 +13,7 @@ MAINTAINER = Alexander Bluhm <bluhm@openbsd.org>
# perl
PERMIT_PACKAGE_CDROM = Yes
PERMIT_PACKAGE_FTP = Yes
PERMIT_DISTFILES_CDROM = Yes
PERMIT_DISTFILES_CDROM =Yes
PERMIT_DISTFILES_FTP = Yes
WANTLIB += c

View File

@ -1,5 +1,2 @@
MD5 (BSD-stat-1.21.tar.gz) = 3Yn7dPVXivQRJPguabmVTQ==
RMD160 (BSD-stat-1.21.tar.gz) = IXWyZmD50sH7PhaCBLB3bbSzQrg=
SHA1 (BSD-stat-1.21.tar.gz) = JeLYP2xVsXpO1eA15EnpvEatRv8=
SHA256 (BSD-stat-1.21.tar.gz) = Z56R1HfciIvcvgSnLL3THzIC3b6OnVa4GWTv17u86xo=
SIZE (BSD-stat-1.21.tar.gz) = 8805
SHA256 (BSD-stat-1.33.tar.gz) = SFVSgwwpIQRXqshvI5vOl1GhdHDVci3TTbMK3X3XbHg=
SIZE (BSD-stat-1.33.tar.gz) = 10479

View File

@ -0,0 +1,36 @@
$OpenBSD: patch-stat_xs,v 1.1 2012/10/21 23:07:12 bluhm Exp $
--- stat.xs.orig Tue Aug 21 12:06:12 2012
+++ stat.xs Wed Sep 26 00:42:32 2012
@@ -7,8 +7,9 @@
#include "XSUB.h"
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
#include <sys/time.h>
+#include <fcntl.h>
+#include <unistd.h>
/*
* Perl prior to 5.6.0 lacks newSVuv()
@@ -137,12 +138,21 @@ xs_utimes(double atime, double mtime, char *path){
static int
xs_lutimes(double atime, double mtime, char *path){
+#ifdef __OpenBSD__
+ struct timespec times[2];
+ times[0].tv_sec = (int)atime;
+ times[0].tv_nsec = (int)((atime - times[0].tv_sec) * 1e9);
+ times[1].tv_sec = (int)mtime;
+ times[1].tv_nsec = (int)((mtime - times[1].tv_sec) * 1e9);
+ int err = utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW);
+#else
struct timeval times[2];
times[0].tv_sec = (int)atime;
times[0].tv_usec = (int)((atime - times[0].tv_sec) * 1e6);
times[1].tv_sec = (int)mtime;
times[1].tv_usec = (int)((mtime - times[1].tv_sec) * 1e6);
int err = lutimes(path, times);
+#endif
return setbang(err);
}

View File

@ -0,0 +1,27 @@
$OpenBSD: patch-t_utimes_t,v 1.1 2012/10/21 23:07:12 bluhm Exp $
--- t/utimes.t.orig Tue Aug 21 12:06:22 2012
+++ t/utimes.t Wed Sep 26 00:28:08 2012
@@ -5,7 +5,7 @@
use strict;
use warnings;
use BSD::stat;
-use Test::More tests => 5;
+use Test::More tests => 8;
use File::Spec;
my $target = File::Spec->catfile('t', "test$$");
@@ -20,8 +20,13 @@ $st = stat($wfh);
close $wfh;
symlink $target, $symlink or die "symlink $target, $symlink : $!";
-ok lutimes(0, 0, $symlink), "lutimes($when, $when, $symlink)";
+ok lutimes(0, 0, $symlink), "lutimes(0, 0, $symlink)";
is lstat($symlink)->mtime, 0, "lutimes() does touch $symlink";
is lstat($target)->mtime, 1234567890, "lutimes() leaves $target";
+
+$when = 1234.5678;
+ok lutimes($when, $when, $symlink), "lutimes($when, $when, $symlink)";
+is lstat($symlink)->mtime, 1234, "lutimes() wrong sec on $symlink";
+is lstat($symlink)->mtimensec, 567800000, "lutimes() wrong nsec on $symlink";
unlink($target, $symlink) == 2 or die "unlink($target, $symlink):$!";