Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Dec 2005 19:38:47 +0100
From:      Gilbert Cao <hika@bsdmon.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Preserve date when cp over smbfs
Message-ID:  <20051230183847.GA9133@bsdmon.com>
In-Reply-To: <20051229155156.GB1075@bsdmon.com>
References:  <20051228112558.GA79302@bsdmon.com> <20051229155156.GB1075@bsdmon.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--wzJLGUyc3ArbnUjN
Content-Type: multipart/mixed; boundary="6TrnltStXW4iwmi0"
Content-Disposition: inline


--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Dec 29, 2005 at 04:51:56PM +0100, Gilbert Cao wrote:
> On Wed, Dec 28, 2005 at 12:25:58PM +0100, Gilbert Cao wrote:
> >=20
> > I have quickly looked into the source code of both cp and gqview, and i=
t seems
> > that cp relies on utimes(), and gqview relies on utime().
> >=20
>=20
> Hi,
> I have finally done my little investigation when applying utime() or utim=
es()
> to a SMB file path :
>=20
> In both case, the access and modification times are preserved.
> So it seems that the cp and tar utilities does not its job about
> preserving times over SMB path (I still don't know why ...).
>=20
> I have a source code example available, if anyone is interested.

Hi, again.
This time, I have done more investigation in the src/bin/cp source code
and I have finally found the problem :

In SMB only case, when utimes() is called *BEFORE* the fd of the newly
created file is close(), it does not do anything.

I have made a little patch to correct this.
So please, committers, can the correction be applied to the cp utility
(Perhaps it is the same problem in the tar utility) ?

I will be very grateful.

--=20
--------------------------------
 (hika) Gilbert Cao
 http://www.miaouirc.com
  - MiaouIRC Project 2002-2003
 http://www.bsdmon.com
  - The BSD DMON Power to serve
 IRC : #miaule at IRCNET Network
--------------------------------

--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="patch_cp_utils.diff"
Content-Transfer-Encoding: quoted-printable

--- ./src/bin/cp/utils.c.orig	Sat Nov 12 22:21:45 2005
+++ ./src/bin/cp/utils.c	Fri Dec 30 19:23:04 2005
@@ -204,8 +204,6 @@
 	 * to remove it if we created it and its length is 0.
 	 */
=20
-	if (pflag && setfile(fs, to_fd))
-		rval =3D 1;
 	if (pflag && preserve_fd_acls(from_fd, to_fd) !=3D 0)
 		rval =3D 1;
 	(void)close(from_fd);
@@ -213,6 +211,14 @@
 		warn("%s", to.p_path);
 		rval =3D 1;
 	}
+	/*
+	 * To preserve times in SMB to.p_path,=20
+	 * setfile() should be call *AFTER* we have closed the file
+	 * descriptors. As we have closed the descriptors, we should
+	 * pass -1 instead of the `to_fd` value
+	 */
+	if (pflag && setfile(fs, -1))
+		rval =3D 1;
 	return (rval);
 }
=20

--6TrnltStXW4iwmi0--

--wzJLGUyc3ArbnUjN
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFDtX62SyQfFTqAEpcRAmQbAKCue9dusLD+gwiT2jb3jcncBljAlQCgujKs
dQ43k1FgMN3bZwTj1LfDxGg=
=0e9J
-----END PGP SIGNATURE-----

--wzJLGUyc3ArbnUjN--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051230183847.GA9133>