this fixes most of the cases, and asserts on the others 

please apply

john

-- 
"Unless everyone else on earth is attending meetings I haven't been told
about."
        - /. paranoia at its finest
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.491
diff -u -p -r1.491 ChangeLog
--- src/ChangeLog       2002/01/04 16:03:52     1.491
+++ src/ChangeLog       2002/01/05 22:08:30
@@ -1,3 +1,7 @@
+2002-01-05  John Levon  <[EMAIL PROTECTED]>
+
+       * vc-backend.C: add FIXME
+ 
 2002-01-04  Juergen Vigna  <[EMAIL PROTECTED]>
 
        * BufferView2.C (lockInset): forgot to set a cursor.
Index: src/vc-backend.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/vc-backend.C,v
retrieving revision 1.18
diff -u -p -r1.18 vc-backend.C
--- src/vc-backend.C    2001/12/18 03:30:35     1.18
+++ src/vc-backend.C    2002/01/05 22:08:31
@@ -254,6 +254,7 @@ void CVS::scanMaster()
                        //sm[4]; // options
                        //sm[5]; // tag or tagdate
                        FileInfo fi(file_);
+                       // FIXME: must double check file is stattable/existing
                        time_t mod = fi.getModificationTime();
                        string mod_date = strip(asctime(gmtime(&mod)), '\n');
                        lyxerr[Debug::LYXVC]
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.219
diff -u -p -r1.219 ChangeLog
--- src/frontends/xforms/ChangeLog      2002/01/04 15:14:22     1.219
+++ src/frontends/xforms/ChangeLog      2002/01/05 22:08:39
@@ -1,3 +1,9 @@
+2002-01-05  John Levon  <[EMAIL PROTECTED]>
+
+       * FormFiledialog.C: add FIXME
+ 
+       * xforms_helpers.C: fix use of FileInfo
+ 
 2002-01-04  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
        * FormDocument.C: Recognize the default paper settings too
Index: src/frontends/xforms/FormCharacter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormCharacter.C,v
retrieving revision 1.17
diff -u -p -r1.17 FormCharacter.C
--- src/frontends/xforms/FormCharacter.C        2001/09/06 12:42:47     1.17
+++ src/frontends/xforms/FormCharacter.C        2002/01/05 22:08:39
@@ -24,8 +24,6 @@
 #include "helper_funcs.h"
 
 using std::vector;
-using std::back_inserter;
-using std::transform;
 using namespace character;
 
 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
Index: src/frontends/xforms/FormFiledialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormFiledialog.C,v
retrieving revision 1.13
diff -u -p -r1.13 FormFiledialog.C
--- src/frontends/xforms/FormFiledialog.C       2001/12/05 08:04:18     1.13
+++ src/frontends/xforms/FormFiledialog.C       2002/01/05 22:08:41
@@ -241,7 +241,6 @@ void FileDialog::Private::Reread()
        iDepth = 0;
        string line, Temp;
        char szMode[15];
-       FileInfo fileInfo;
        string File = pszDirectory;
        if (File != "/") {
                File = split(File, Temp, '/');
@@ -276,7 +275,8 @@ void FileDialog::Private::Reread()
                // gets file status
                File = AddName(pszDirectory, fname);
 
-               fileInfo.newFile(File, true);
+               // FIXME: we don't get this file exists/stattable
+               FileInfo fileInfo(File, true);
                fileInfo.modeString(szMode);
                unsigned int nlink = fileInfo.getNumberOfLinks();
                string user =   lyxUserCache.find(fileInfo.getUid());
Index: src/frontends/xforms/xforms_helpers.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/xforms_helpers.C,v
retrieving revision 1.23
diff -u -p -r1.23 xforms_helpers.C
--- src/frontends/xforms/xforms_helpers.C       2001/12/12 09:56:02     1.23
+++ src/frontends/xforms/xforms_helpers.C       2002/01/05 22:08:44
@@ -400,7 +400,7 @@ bool RWInfo::WriteableDir(string const &
        }
 
        FileInfo const tp(name);
-       if (!tp.isDir()) {
+       if (!tp.isOK() || !tp.isDir()) {
                error_message = N_("Directory does not exist.");
                return false;
        }
@@ -424,7 +424,7 @@ bool RWInfo::ReadableDir(string const & 
        }
 
        FileInfo const tp(name);
-       if (!tp.isDir()) {
+       if (!tp.isOK() || !tp.isDir()) {
                error_message = N_("Directory does not exist.");
                return false;
        }
@@ -459,7 +459,10 @@ bool RWInfo::WriteableFile(string const 
        }
 
        FileInfo d(name);
-       if (!d.isDir()) {
+
+       // FIXME: what is this supposed to do ?
+       // .newFile doesn't do what you think it does ... 
+       if (!d.isOK() || !d.isDir()) {
                d.newFile(dir);
        }
 
@@ -474,12 +477,12 @@ bool RWInfo::WriteableFile(string const 
        }
 
        FileInfo f(name);
-       if (dir == name || f.isDir()) {
+       if (dir == name || (f.isOK() && f.isDir())) {
                error_message = N_("A file is required, not a directory.");
                return false;
        }
 
-       if (f.exist() && !f.writable()) {
+       if (f.isOK() && f.exist() && !f.writable()) {
                error_message = N_("Cannot write to this file.");
                return false;
        }
@@ -504,7 +507,8 @@ bool RWInfo::ReadableFile(string const &
        }
 
        FileInfo d(name);
-       if (!d.isDir()) {
+       // FIXME: what is this supposed to do ?
+       if (!d.isOK() && !d.isDir()) {
                d.newFile(dir);
        }
 
@@ -519,7 +523,7 @@ bool RWInfo::ReadableFile(string const &
        }
 
        FileInfo f(name);
-       if (dir == name || f.isDir()) {
+       if (dir == name || (f.isOK() && f.isDir())) {
                error_message = N_("A file is required, not a directory.");
                return false;
        }
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.266
diff -u -p -r1.266 ChangeLog
--- src/insets/ChangeLog        2002/01/04 16:03:53     1.266
+++ src/insets/ChangeLog        2002/01/05 22:08:51
@@ -1,3 +1,7 @@
+2002-01-05  John Levon  <[EMAIL PROTECTED]>
+
+       * insetinclude.C: fix use of FileInfo
+ 
 2002-01-04  Juergen Vigna  <[EMAIL PROTECTED]>
 
        * insettext.C (lockInsetInInset): forgot to set a cursor.
Index: src/insets/insetinclude.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.C,v
retrieving revision 1.64
diff -u -p -r1.64 insetinclude.C
--- src/insets/insetinclude.C   2001/12/28 13:26:54     1.64
+++ src/insets/insetinclude.C   2002/01/05 22:08:52
@@ -218,7 +218,7 @@ bool InsetInclude::loadIfNeeded() const
        
        // the readonly flag can/will be wrong, not anymore I think.
        FileInfo finfo(getFileName());
-       bool const ro = !finfo.writable();
+       bool const ro = !(!finfo.isOK() || finfo.writable());
        return bufferlist.readFile(getFileName(), ro) != 0;
 }
 
Index: src/support/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/ChangeLog,v
retrieving revision 1.53
diff -u -p -r1.53 ChangeLog
--- src/support/ChangeLog       2001/12/20 16:27:02     1.53
+++ src/support/ChangeLog       2002/01/05 22:08:59
@@ -1,3 +1,10 @@
+2002-01-05  John Levon  <[EMAIL PROTECTED]>
+
+       * filetools.C: fix use of FileInfo
+
+       * FileInfo.h:
+       * FileInfo.C: add Asserts and documentation
+ 
 2001-12-20  Kayvan A. Sylvan  <[EMAIL PROTECTED]>
 
        * os_win32.C: compilation fixes
Index: src/support/FileInfo.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/FileInfo.C,v
retrieving revision 1.13
diff -u -p -r1.13 FileInfo.C
--- src/support/FileInfo.C      2001/06/14 08:20:41     1.13
+++ src/support/FileInfo.C      2002/01/05 22:08:59
@@ -19,6 +19,7 @@
 
 #include <cerrno>
 #include "FileInfo.h"
+#include "LAssert.h"
 
 #if !S_IRUSR
 # if S_IREAD
@@ -174,6 +175,8 @@ FileInfo & FileInfo::newFile(int fildes)
 // should not be in FileInfo
 char const * FileInfo::typeIndicator() const
 {
+       lyx::Assert(isOK());
+ 
        if (S_ISDIR(buf.st_mode)) return ("/");
 #ifdef S_ISLNK
        if (S_ISLNK(buf.st_mode)) return ("@");
@@ -192,6 +195,8 @@ char const * FileInfo::typeIndicator() c
 
 mode_t FileInfo::getMode() const
 {
+       lyx::Assert(isOK());
+ 
        return buf.st_mode;
 }
 
@@ -211,6 +216,8 @@ void FileInfo::modeString(char * szStrin
 // should not be in FileInfo
 char FileInfo::typeLetter() const
 {
+       lyx::Assert(isOK());
+ 
 #ifdef S_ISBLK
        if (S_ISBLK(buf.st_mode)) return 'b';
 #endif
@@ -248,6 +255,8 @@ void FileInfo::flagRWX(mode_t i, char * 
 // should not be in FileInfo
 void FileInfo::setSticky(char * szString) const
 {
+       lyx::Assert(isOK());
+ 
 #ifdef S_ISUID
        if (buf.st_mode & S_ISUID) {
                if (szString[3] != 'x') szString[3] = 'S';
@@ -271,42 +280,49 @@ void FileInfo::setSticky(char * szString
 
 time_t FileInfo::getModificationTime() const
 {
+       lyx::Assert(isOK());
        return buf.st_mtime;
 }
 
 
 time_t FileInfo::getAccessTime() const
 {
+       lyx::Assert(isOK());
        return buf.st_atime;
 }
 
 
 time_t FileInfo::getStatusChangeTime() const
 {
+       lyx::Assert(isOK());
        return buf.st_ctime;
 }
 
 
 nlink_t FileInfo::getNumberOfLinks() const
 {
+       lyx::Assert(isOK());
        return buf.st_nlink;
 }
 
 
 uid_t FileInfo::getUid() const
 {
+       lyx::Assert(isOK());
        return buf.st_uid;
 }
 
 
 gid_t FileInfo::getGid() const
 {
+       lyx::Assert(isOK());
        return buf.st_gid;
 }
 
 
 off_t FileInfo::getSize() const
 {
+       lyx::Assert(isOK());
        return buf.st_size;
 }
 
@@ -328,42 +344,49 @@ bool FileInfo::isOK() const
 
 bool FileInfo::isLink() const
 {
+       lyx::Assert(isOK());
        return S_ISLNK(buf.st_mode);
 }
 
 
 bool FileInfo::isRegular() const
 {
+       lyx::Assert(isOK());
        return S_ISREG(buf.st_mode);
 }
 
 
 bool FileInfo::isDir() const
 {
+       lyx::Assert(isOK());
        return S_ISDIR(buf.st_mode);
 }
 
 
 bool FileInfo::isChar() const
 {
+       lyx::Assert(isOK());
        return S_ISCHR(buf.st_mode);
 }
 
 
 bool FileInfo::isBlock() const
 {
+       lyx::Assert(isOK());
        return S_ISBLK(buf.st_mode);
 }
 
 
 bool FileInfo::isFifo() const
 {
+       lyx::Assert(isOK());
        return S_ISFIFO(buf.st_mode);
 }
 
 
 bool FileInfo::isSocket() const
 {
+       lyx::Assert(isOK());
 #ifdef S_ISSOCK
        return S_ISSOCK(buf.st_mode);
 #else
@@ -386,6 +409,3 @@ bool FileInfo::access(int p) const
                return false;
        }
 }
-
-
-
Index: src/support/FileInfo.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/FileInfo.h,v
retrieving revision 1.17
diff -u -p -r1.17 FileInfo.h
--- src/support/FileInfo.h      2001/05/30 13:53:44     1.17
+++ src/support/FileInfo.h      2002/01/05 22:08:59
@@ -30,6 +30,9 @@
 #endif
 
 /** Use objects of this class to get information about files.
+ *
+ * Users must make sure to check fi.isOK() before any operations
+ * requiring the file to exist such as fi.isDir()
  */
 class FileInfo : boost::noncopyable {
 public:
Index: src/support/filetools.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v
retrieving revision 1.91
diff -u -p -r1.91 filetools.C
--- src/support/filetools.C     2001/12/05 08:04:19     1.91
+++ src/support/filetools.C     2002/01/05 22:09:02
@@ -435,7 +435,8 @@ int DeleteAllFilesInDir (string const & 
                                     << endl;
 
                bool deleted = true;
-               if (FileInfo(unlinkpath).isDir())
+               FileInfo fi(unlinkpath);
+               if (fi.isOK() && fi.isDir())
                        deleted = (DeleteAllFilesInDir(unlinkpath) == 0);
                deleted &= (lyx::unlink(unlinkpath) == 0);
                if (!deleted) {

Reply via email to