From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 1D8D3BC69 for ; Thu, 2 Aug 2007 16:37:00 +0200 (CEST) Received: from smtp7-g19.free.fr (smtp7-g19.free.fr [212.27.42.64]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l72Eaxjt011099 for ; Thu, 2 Aug 2007 16:36:59 +0200 Received: from smtp7-g19.free.fr (localhost [127.0.0.1]) by smtp7-g19.free.fr (Postfix) with ESMTP id 68CB71A385; Thu, 2 Aug 2007 16:36:59 +0200 (CEST) Received: from [192.168.144.128] (lns-bzn-45-82-65-144-27.adsl.proxad.net [82.65.144.27]) by smtp7-g19.free.fr (Postfix) with ESMTP id E9E891A37E; Thu, 2 Aug 2007 16:36:58 +0200 (CEST) Message-ID: <46B1EC05.9060508@univ-savoie.fr> Date: Thu, 02 Aug 2007 16:36:53 +0200 From: Christophe Raffalli User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Correnson_Lo=EFc?= , caml-list@inria.fr Subject: Re: [Caml-list] absolute_name ? References: <46A0E915.1000903@univ-savoie.fr> <46B1BCD1.9030004@trusted-labs.fr> In-Reply-To: <46B1BCD1.9030004@trusted-labs.fr> X-Enigmail-Version: 0.94.2.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigBB280A1AE2E16FEEFF093249" X-Miltered: at concorde with ID 46B1EC0B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 correnson:01 getcwd:01 basename:01 dirname:01 getcwd:01 chdir:01 chdir:01 basename:01 cheers:01 equality:01 X-Attachments: cset="utf-8" name="Christophe.Raffalli.vcf" name="Christophe.Raffalli.vcf" type="application/pgp-signature" name="signature.asc" name="signature.asc" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigBB280A1AE2E16FEEFF093249 Content-Type: multipart/mixed; boundary="------------050000090303060707090101" This is a multi-part message in MIME format. --------------050000090303060707090101 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Correnson Lo=EFc a =E9crit : > On Win32, you may have to handle short vs long names. > For instance, 'C:\PROGRA~2' may be the same path to 'C:\Program Files',= > or may be not. When using absolute paths for equality, you can go into > troubles. > L. >=20 I just want a name that can be saved and is independent from the current = directory. Testing absolute filename for equality is always a bad idea, here are a f= ew reasons: - symbolic link - physical link - case insensitive system (like OS X) - short names on windows (the one you mentionned) However, you can store an absolute name, together with a MD5 to check if = a file has changed since the last access. I think this is pretty safe. You can use the following code (which is simpler than the one I submitted= previously) let absolute_name str =3D if Filename.is_relative str then Filename.concat (Sys.getcwd ()) str else str But it can produce filename not in "normal form" (like "/home/user/./fold= er/toto.ml"). Moreover, I wanted to check that the folder exists but I did not want to = check is the file itself exists. So my original code is not so bad: let absolute_name str =3D let base =3D Filename.basename str in let dir =3D Filename.dirname str in let saved_dir =3D Sys.getcwd () in try Sys.chdir dir; let res =3D Filename.concat (Sys.getcwd ()) base in Sys.chdir saved_dir; res with | Sys_error _ -> str In fact this function is not too far from converting any filename to a unique absolute filename independent from the original filename. It deals with symbolic link for folder correctly because Sys.getcwd () gi= ves a "real" path. It does not solve the problem of physical link (I am not s= ure one want to solve that one) nor the problem of case insensitive filesyste= m, nor symbolic link for the basename itself. Anyway, the second function above seems to suits my needs (although I have not tested it under windows yet). Cheers, Christophe --------------050000090303060707090101 Content-Type: text/x-vcard; charset=utf-8; name="Christophe.Raffalli.vcf" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Christophe.Raffalli.vcf" begin:vcard fn:Christophe Raffalli n:Raffalli;Christophe org:LAMA (UMR 5127) email;internet:Christophe.Raffalli@univ-savoie.fr title;quoted-printable:Ma=3DC3=3DAEtre de conf=3DC3=3DA9rences tel;work:+33 4 79 75 81 03 note;quoted-printable:Message sign=3DC3=3DA9 cryptographiquement avec pgp= , la clef publique est sur=3D subkeys.pgp.net x-mozilla-html:TRUE version:2.1 end:vcard --------------050000090303060707090101-- --------------enigBB280A1AE2E16FEEFF093249 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGsewJi9jr/RgYAS4RAmWEAJ9imNdC60KkjB2GCtTUWwxsBo6ATwCdGfCN wMnrY+MgClYwtcUTjAIkWYg= =gsn6 -----END PGP SIGNATURE----- --------------enigBB280A1AE2E16FEEFF093249--