]> git.lyx.org Git - features.git/commitdiff
fix IsFileWriteable, implement the file_not_found_hook and make it work for RCS
authorLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 11 Jan 2000 08:23:07 +0000 (08:23 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 11 Jan 2000 08:23:07 +0000 (08:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@413 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/bufferlist.C
src/lyxvc.C
src/support/filetools.C
src/vc-backend.C
src/vc-backend.h

index 93ce9b0b8819e8f744f8efa9f0a41aac266e8f3b..17874f0c668cfbeaf4c4e0c9e1230c8835a8f663 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2000-01-11  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * src/vc-backend.C (doVCCommand): change to be static and take one
+       more parameter: the path to chdir too be fore executing the command.
+       (retrive): new function equiv to "co -r"
+
+       * src/bufferlist.C (loadLyXFile): implement the missing parts if
+       file_not_found_hook is true.
+
+       * src/lyxvc.C (file_not_found_hook): implement file_not_found_hook.
+
+       * src/support/filetools.C (IsFileWriteable): use FileInfo to check
+       if a file is readwrite,readonly...anything else.
+
 2000-01-10  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
        * src/lyx_cb.C (MakeLaTeXOutput): name change from MakeDVIOutput
index 1a0eb00df668f3ed38cc9e33ef83afee14b52668..877568e62036910fa9d98fb0fd79c210a882a052 100644 (file)
@@ -36,6 +36,7 @@
 #include "lyx_cb.h"
 #include "gettext.h"
 #include "LyXView.h"
+#include "vc-backend.h"
 
 extern BufferView * current_view;
 extern int RunLinuxDoc(int, string const &);
@@ -596,7 +597,13 @@ Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
                if (LyXVC::file_not_found_hook(s)) {
                        // Ask if the file should be checked out for
                        // viewing/editing, if so: load it.
-                       lyxerr << "Do you want to checkout?" << endl;
+                       if (AskQuestion(_("Do you want to retrive file under version control?"))) {
+                               // How can we know _how_ to do the checkout?
+                               // With the current VC support it has to be,
+                               // a RCS file since CVS do not have special ,v files.
+                               RCS::retrive(s);
+                               return loadLyXFile(filename, tolastfiles);
+                       }
                }
                if (AskQuestion(_("Cannot open specified file:"), 
                                MakeDisplayPath(s, 50),
index a577c7f8edd6c9f94d2956677c075f128690037e..3097069d6652395bf4ad3c250e130d8188bdf171 100644 (file)
@@ -59,9 +59,13 @@ bool LyXVC::file_found_hook(string const & fn)
 }
 
 
-bool LyXVC::file_not_found_hook(string const &)
+bool LyXVC::file_not_found_hook(string const & fn)
 {
-       // file is not under any VCS.
+       // Check if file is under RCS
+       if (!RCS::find_file(fn).empty())
+               return true;
+       if (!CVS::find_file(fn).empty())
+               return true;
        return false;
 }
 
index 5f3e939d2045c38d9c371d5ba3a8dcaad0a59151..1d3831c43ebc38c3ab451a097d33605e485869fd 100644 (file)
@@ -17,9 +17,6 @@
 #include <config.h>
 
 #include <cctype>
-#include <fstream>
-using std::fstream;
-using std::ios;
 
 #include <utility>
 using std::make_pair;
@@ -157,15 +154,12 @@ bool IsFileReadable (string const & path)
 //      -1 error (doesn't exist, no access, anything else) 
 int IsFileWriteable (string const & path)
 {
-       fstream fs(path.c_str(), ios::out|ios::ate);
-       if (!fs) {
-               fs.open(path.c_str(), ios::in|ios::ate);
-               if (fs)
-                       return 0;
-               else
-                       return -1;
-       }
-       return 1;
+       FileInfo fi(path);
+       if (fi.access(FileInfo::wperm|FileInfo::rperm)) // read-write
+               return 1;
+       if (fi.readable()) // read-only
+               return 0;
+       return -1; // everything else.
 }
 
 
index b23f30e14f0683b0800033dddf63768bbbee0762..d1608894fdcbda376e8ff459eabc7bb21fd22d59 100644 (file)
@@ -18,11 +18,11 @@ using std::ifstream;
 #include "lyxfunc.h"
 
 
-int VCS::doVCCommand(string const & cmd)
+int VCS::doVCCommand(string const & cmd, string const & path)
 {
        lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
         Systemcalls one;
-       Path p(owner_->filepath);
+       Path p(path);
        int ret = one.startscript(Systemcalls::System, cmd);
        return ret;
 }
@@ -63,6 +63,15 @@ string RCS::find_file(string const & file)
 }
 
 
+void RCS::retrive(string const & file)
+{
+       lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
+       VCS::doVCCommand("co -q -r \""
+                        + file + "\"",
+                        string());
+}
+
+
 void RCS::scanMaster()
 {
        lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
@@ -133,7 +142,7 @@ void RCS::registrer(string const & msg)
        cmd += "\" \"";
        cmd += OnlyFilename(owner_->fileName());
        cmd += "\"";
-       doVCCommand(cmd);
+       doVCCommand(cmd, owner_->filepath);
        owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
 }
 
@@ -141,7 +150,7 @@ void RCS::registrer(string const & msg)
 void RCS::checkIn(string const & msg)
 {
        doVCCommand("ci -q -u -m\"" + msg + "\" \""
-                   + OnlyFilename(owner_->fileName()) + "\"");
+                   + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
        owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
 }
 
@@ -150,7 +159,7 @@ void RCS::checkOut()
 {
        owner_->markLyxClean();
        doVCCommand("co -q -l \""
-                   + OnlyFilename(owner_->fileName()) + "\"");
+                   + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
        owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
 }
 
@@ -158,7 +167,7 @@ void RCS::checkOut()
 void RCS::revert()
 {
        doVCCommand("co -f -u" + version() + " \""
-                   + OnlyFilename(owner_->fileName()) + "\"");
+                   + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
        // We ignore changes and just reload!
        owner_->markLyxClean();
        owner_->getUser()->owner()
@@ -170,14 +179,14 @@ void RCS::undoLast()
 {
        lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
        doVCCommand("rcs -o" + version() + " \""
-                   + OnlyFilename(owner_->fileName()) + "\"");
+                   + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
 }
 
 
 void RCS::getLog(string const & tmpf)
 {
        doVCCommand("rlog \""
-                   + OnlyFilename(owner_->fileName()) + "\" > " + tmpf);
+                   + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
 }
 
 
@@ -263,7 +272,7 @@ void CVS::scanMaster()
 void CVS::registrer(string const & msg)
 {
        doVCCommand("cvs -q add -m \"" + msg + "\" \""
-                   + OnlyFilename(owner_->fileName()) + "\"");
+                   + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
        owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
 }
 
@@ -271,7 +280,7 @@ void CVS::registrer(string const & msg)
 void CVS::checkIn(string const & msg)
 {
        doVCCommand("cvs -q commit -m \"" + msg + "\" \""
-                   + OnlyFilename(owner_->fileName()) + "\"");
+                   + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
        owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
 }
 
index 77e6c6cd1e68b56fd4444e9b0743d6dad6fdae74..78e5d36a2ba3362e47c4a7b250910fb8fcfc4bd6 100644 (file)
@@ -50,7 +50,7 @@ public:
        VCStatus stat() const { return vcstat; }
 protected:
        ///
-       int doVCCommand(string const &);
+       static int doVCCommand(string const &, string const &);
 
        /** The master VC file. For RCS this is *,v or RCS/ *,v. master should
            have full path.
@@ -80,6 +80,8 @@ public:
        ///
        static string find_file(string const & file);
        ///
+       static void retrive(string const & file);
+       ///
        virtual void scanMaster();
        ///
        virtual void registrer(string const & msg);