[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-devel
Subject:    Request for more help
From:       Angus Leeming <leeming () lyx ! org>
Date:       2004-12-23 8:58:06
Message-ID: cqe179$93u$1 () sea ! gmane ! org
[Download RAW message or body]

I believe that this code is testing whether either the lyx executable or
the directory in which it is found is a symbolic link. (Hence the two
blocks.) Questions:

1. Why, in the case of the directory being a symbolic link, is the link
followed recursively until the actual link target is found. Or rather, why
is only the first link followed in the case of the executable name.

2. In the case of the executable itself being a symbolic link, only
"../share" of the path to the symbolic link is a possible base for
system_lyxdir. What about MAcOS's "../Resources"? Why is that added
unconditionally?

Oh, it's all too confusing !! I'm sure it doesn't need to be so obfuscated.

Angus

 string binpath = os::binpath();
 string binname = os::binname();
 // Leave to one side the fact that this is not true if
 // a "/.libs/" suffix has been stripped from @c binpath.
 string fullbinname = MakeAbsPath(binname, binpath);

 // Path of binary/../Resources/
 searchpath += NormalizePath(AddPath(binpath, "../Resources/") + 
        OnlyFilename(binname)) + ';';

 string fullbinpath = binpath;
 FileInfo file(fullbinname, true);
 if (file.isLink()) {
  lyxerr[Debug::INIT] << "binary is a link" << endl;
  string link;
  if (LyXReadLink(fullbinname, link, true)) {
   // Path of binary/../share/name of binary/
   searchpath += NormalizePath(AddPath(binpath,
           "../share/")
          + OnlyFilename(binname));
   searchpath += ';';
   fullbinpath = link;
   binpath = MakeAbsPath(OnlyPath(fullbinpath));
  }
 }

 bool followlink;
 do {
  // Path of binary/../share/name of binary/
  string const exe_name = OnlyFilename(binname);
#ifdef _WIN32
  string const lyx_system_dir_name =
   suffixIs(exe_name, ".exe") ?
    ChangeExtension(exe_name, "") :
    exe_name;
#else
  string const lyx_system_dir_name = exe_name;
#endif
  string const shared_dir_name =
   NormalizePath(AddPath(binpath, "../share/"));
  searchpath += shared_dir_name + lyx_system_dir_name + ';';

  // Follow Symlinks
  FileInfo file(fullbinpath, true);
  followlink = file.isLink();
  if (followlink) {
   lyxerr[Debug::INIT] << " directory " << fullbinpath
         << " is a link" << endl;
   string link;
   if (LyXReadLink(fullbinpath, link, true)) {
    fullbinpath = link;
    binpath = MakeAbsPath(OnlyPath(fullbinpath));
   }
   else {
    followlink = false;
   }
  }
 } while (followlink);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic