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
This commit is contained in:
Lars Gullik Bjønnes 2000-01-11 08:23:07 +00:00
parent e656d12d0b
commit 18b8221ede
6 changed files with 56 additions and 26 deletions

View File

@ -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> 2000-01-10 Lars Gullik Bjřnnes <larsbj@lyx.org>
* src/lyx_cb.C (MakeLaTeXOutput): name change from MakeDVIOutput * src/lyx_cb.C (MakeLaTeXOutput): name change from MakeDVIOutput

View File

@ -36,6 +36,7 @@
#include "lyx_cb.h" #include "lyx_cb.h"
#include "gettext.h" #include "gettext.h"
#include "LyXView.h" #include "LyXView.h"
#include "vc-backend.h"
extern BufferView * current_view; extern BufferView * current_view;
extern int RunLinuxDoc(int, string const &); 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)) { if (LyXVC::file_not_found_hook(s)) {
// Ask if the file should be checked out for // Ask if the file should be checked out for
// viewing/editing, if so: load it. // 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:"), if (AskQuestion(_("Cannot open specified file:"),
MakeDisplayPath(s, 50), MakeDisplayPath(s, 50),

View 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; return false;
} }

View File

@ -17,9 +17,6 @@
#include <config.h> #include <config.h>
#include <cctype> #include <cctype>
#include <fstream>
using std::fstream;
using std::ios;
#include <utility> #include <utility>
using std::make_pair; using std::make_pair;
@ -157,15 +154,12 @@ bool IsFileReadable (string const & path)
// -1 error (doesn't exist, no access, anything else) // -1 error (doesn't exist, no access, anything else)
int IsFileWriteable (string const & path) int IsFileWriteable (string const & path)
{ {
fstream fs(path.c_str(), ios::out|ios::ate); FileInfo fi(path);
if (!fs) { if (fi.access(FileInfo::wperm|FileInfo::rperm)) // read-write
fs.open(path.c_str(), ios::in|ios::ate); return 1;
if (fs) if (fi.readable()) // read-only
return 0; return 0;
else return -1; // everything else.
return -1;
}
return 1;
} }

View File

@ -18,11 +18,11 @@ using std::ifstream;
#include "lyxfunc.h" #include "lyxfunc.h"
int VCS::doVCCommand(string const & cmd) int VCS::doVCCommand(string const & cmd, string const & path)
{ {
lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl; lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
Systemcalls one; Systemcalls one;
Path p(owner_->filepath); Path p(path);
int ret = one.startscript(Systemcalls::System, cmd); int ret = one.startscript(Systemcalls::System, cmd);
return ret; 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() void RCS::scanMaster()
{ {
lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl; lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
@ -133,7 +142,7 @@ void RCS::registrer(string const & msg)
cmd += "\" \""; cmd += "\" \"";
cmd += OnlyFilename(owner_->fileName()); cmd += OnlyFilename(owner_->fileName());
cmd += "\""; cmd += "\"";
doVCCommand(cmd); doVCCommand(cmd, owner_->filepath);
owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload"); owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
} }
@ -141,7 +150,7 @@ void RCS::registrer(string const & msg)
void RCS::checkIn(string const & msg) void RCS::checkIn(string const & msg)
{ {
doVCCommand("ci -q -u -m\"" + msg + "\" \"" doVCCommand("ci -q -u -m\"" + msg + "\" \""
+ OnlyFilename(owner_->fileName()) + "\""); + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload"); owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
} }
@ -150,7 +159,7 @@ void RCS::checkOut()
{ {
owner_->markLyxClean(); owner_->markLyxClean();
doVCCommand("co -q -l \"" doVCCommand("co -q -l \""
+ OnlyFilename(owner_->fileName()) + "\""); + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload"); owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
} }
@ -158,7 +167,7 @@ void RCS::checkOut()
void RCS::revert() void RCS::revert()
{ {
doVCCommand("co -f -u" + version() + " \"" doVCCommand("co -f -u" + version() + " \""
+ OnlyFilename(owner_->fileName()) + "\""); + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
// We ignore changes and just reload! // We ignore changes and just reload!
owner_->markLyxClean(); owner_->markLyxClean();
owner_->getUser()->owner() owner_->getUser()->owner()
@ -170,14 +179,14 @@ void RCS::undoLast()
{ {
lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl; lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
doVCCommand("rcs -o" + version() + " \"" doVCCommand("rcs -o" + version() + " \""
+ OnlyFilename(owner_->fileName()) + "\""); + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
} }
void RCS::getLog(string const & tmpf) void RCS::getLog(string const & tmpf)
{ {
doVCCommand("rlog \"" 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) void CVS::registrer(string const & msg)
{ {
doVCCommand("cvs -q add -m \"" + msg + "\" \"" doVCCommand("cvs -q add -m \"" + msg + "\" \""
+ OnlyFilename(owner_->fileName()) + "\""); + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload"); owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
} }
@ -271,7 +280,7 @@ void CVS::registrer(string const & msg)
void CVS::checkIn(string const & msg) void CVS::checkIn(string const & msg)
{ {
doVCCommand("cvs -q commit -m \"" + msg + "\" \"" doVCCommand("cvs -q commit -m \"" + msg + "\" \""
+ OnlyFilename(owner_->fileName()) + "\""); + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload"); owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
} }

View File

@ -50,7 +50,7 @@ public:
VCStatus stat() const { return vcstat; } VCStatus stat() const { return vcstat; }
protected: 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 /** The master VC file. For RCS this is *,v or RCS/ *,v. master should
have full path. have full path.
@ -80,6 +80,8 @@ public:
/// ///
static string find_file(string const & file); static string find_file(string const & file);
/// ///
static void retrive(string const & file);
///
virtual void scanMaster(); virtual void scanMaster();
/// ///
virtual void registrer(string const & msg); virtual void registrer(string const & msg);