From: Lars Gullik Bjønnes Date: Tue, 11 Jan 2000 08:23:07 +0000 (+0000) Subject: fix IsFileWriteable, implement the file_not_found_hook and make it work for RCS X-Git-Tag: 1.6.10~22435 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=18b8221ede82350caa51cc7db33a1f874b4e7396;p=features.git fix IsFileWriteable, implement the file_not_found_hook and make it work for RCS git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@413 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 93ce9b0b88..17874f0c66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2000-01-11 Lars Gullik Bjønnes + + * 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 * src/lyx_cb.C (MakeLaTeXOutput): name change from MakeDVIOutput diff --git a/src/bufferlist.C b/src/bufferlist.C index 1a0eb00df6..877568e620 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -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), diff --git a/src/lyxvc.C b/src/lyxvc.C index a577c7f8ed..3097069d66 100644 --- a/src/lyxvc.C +++ b/src/lyxvc.C @@ -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; } diff --git a/src/support/filetools.C b/src/support/filetools.C index 5f3e939d20..1d3831c43e 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -17,9 +17,6 @@ #include #include -#include -using std::fstream; -using std::ios; #include 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. } diff --git a/src/vc-backend.C b/src/vc-backend.C index b23f30e14f..d1608894fd 100644 --- a/src/vc-backend.C +++ b/src/vc-backend.C @@ -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"); } diff --git a/src/vc-backend.h b/src/vc-backend.h index 77e6c6cd1e..78e5d36a2b 100644 --- a/src/vc-backend.h +++ b/src/vc-backend.h @@ -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);