Add new copyFileToDir helper function.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7091 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-06-03 10:14:52 +00:00
parent 5b4e90488c
commit 6412ac52b6
4 changed files with 52 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2003-06-02 Angus Leeming <leeming@lyx.org>
* filetools.[Ch] (copyFileToDir): new helper function.
* os.h: remove trailing semi-colon from end of namespace os block.
2003-06-01 Angus Leeming <leeming@lyx.org>
* filetools.h (LibScriptSearch): give the function a meaningful

View File

@ -1320,3 +1320,40 @@ string const readBB_from_PSFile(string const & file)
readBB_lyxerrMessage(file_, zipped, "no bb found");
return string();
}
string copyFileToDir(string const & path, string const & file_in)
{
lyx::Assert(AbsolutePath(path));
// First, make the file path relative to path.
string file_out = MakeRelPath(path, NormalizePath(file_in));
file_out = os::slashify_path(file_out);
// Now generate a unique filename.
// Remove the extension.
file_out = ChangeExtension(file_out, string());
// Replace '/' in the file name with '_'
file_out = subst(file_out, "/", "_");
// Replace '.' in the file name with '_'
file_out = subst(file_out, ".", "_");
// Add the extension back on
file_out = ChangeExtension(file_out, GetExtension(file_in));
// Put this file in the buffer's temp dir
file_out = MakeAbsPath(file_out, path);
// If the original is newer than the copy, then copy the original
// to the new directory.
FileInfo fi(file_in);
FileInfo fi2(file_out);
bool success = true;
if (fi.exist()) {
if (!fi2.exist() ||
difftime(fi.getModificationTime(),
fi2.getModificationTime()) >= 0)
success = lyx::copy(file_in, file_out);
}
return success ? file_out : string();
}

View File

@ -11,6 +11,7 @@
#include <vector>
#include <utility>
#include "LString.h"
#include "os.h"
/// remove directory and all contents, returns 0 on success
@ -200,6 +201,13 @@ void removeAutosaveFile(string const & filename);
/// read the BoundingBox entry from a ps/eps/pdf-file
string const readBB_from_PSFile(string const & file);
/** Copy \param file to directory \param path. The file name is manipulated
so that eg some/path/to/file becomes some_path_to_file.
\returns this file name if the file is copied successfully, else
\returns an empty string.
*/
string copyFileToDir(string const & path, string const & file);
typedef std::pair<int, string> cmd_ret;
cmd_ret const RunCommand(string const & cmd);

View File

@ -43,6 +43,6 @@ namespace os {
char const * popen_read_mode();
//
void warn(string const & mesg);
};
}
#endif