caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
To: "Correnson Loïc" <Loic.Correnson@trusted-labs.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] absolute_name ?
Date: Thu, 02 Aug 2007 16:36:53 +0200	[thread overview]
Message-ID: <46B1EC05.9060508@univ-savoie.fr> (raw)
In-Reply-To: <46B1BCD1.9030004@trusted-labs.fr>


[-- Attachment #1.1: Type: text/plain, Size: 1985 bytes --]

Correnson Loïc a écrit :
> 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.
> 

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 few 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 =
  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/./folder/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 =
  let base = Filename.basename str in
  let dir = Filename.dirname str in
  let saved_dir = Sys.getcwd () in
  try Sys.chdir dir;
    let res = 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 () gives
a "real" path. It does not solve the problem of physical link (I am not sure
one want to solve that one) nor the problem of case insensitive filesystem, 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




[-- Attachment #1.2: Christophe.Raffalli.vcf --]
[-- Type: text/x-vcard, Size: 380 bytes --]

begin:vcard
fn:Christophe Raffalli
n:Raffalli;Christophe
org:LAMA (UMR 5127)
email;internet:Christophe.Raffalli@univ-savoie.fr
title;quoted-printable:Ma=C3=AEtre de conf=C3=A9rences
tel;work:+33 4 79 75 81 03
note;quoted-printable:Message sign=C3=A9 cryptographiquement avec pgp, la clef publique est sur=
	 subkeys.pgp.net
x-mozilla-html:TRUE
version:2.1
end:vcard


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

  parent reply	other threads:[~2007-08-02 14:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-20 16:55 Christophe Raffalli
2007-07-20 21:23 ` Sylvain Le Gall
     [not found] ` <46B1BCD1.9030004@trusted-labs.fr>
2007-08-02 14:36   ` Christophe Raffalli [this message]
2007-08-02 16:21     ` [Caml-list] " skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46B1EC05.9060508@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=Loic.Correnson@trusted-labs.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).