Fix another instance of filename encoding problems

* src/support/filetools.h
	(fileSearch): change return value type to vector<FileName>

	* src/support/filetools.C
	(dirList): Convert filenames from the file system encoding

	* src/converter.C
	(Converters::move): Adjust to dirList interface change

	* src/support/filename.[Ch]
	(FileName::fromFilesystemEncoding): New static method

	* src/client/client.C: Add comments about filename encoding


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16362 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-12-21 13:01:47 +00:00
parent a1389d411c
commit 49b753f603
6 changed files with 39 additions and 19 deletions

View File

@ -85,8 +85,9 @@ string itoa(unsigned int i)
}
// Parts stolen from lyx::support::DirList()
// Returns the absolute pathnames of all lyx local sockets
/// Returns the absolute pathnames of all lyx local sockets in
/// file system encoding.
/// Parts stolen from lyx::support::DirList().
vector<fs::path> lyxSockets(string const & dir, string const & pid)
{
vector<fs::path> dirlist;
@ -118,6 +119,8 @@ vector<fs::path> lyxSockets(string const & dir, string const & pid)
namespace socktools {
/// Connect to the socket \p name.
/// Caution: \p name is in filesystem encoding
int connect(string const & name)
{
int fd; // File descriptor for the socket
@ -551,6 +554,7 @@ int main(int argc, char * argv[])
vector<fs::path>::const_iterator addr = addrs.begin();
vector<fs::path>::const_iterator end = addrs.end();
for (; addr != end; ++addr) {
// Caution: addr->string() is in filesystem encoding
server.reset(new LyXDataSocket(addr->string()));
if (server->connected())
break;

View File

@ -512,30 +512,33 @@ bool Converters::move(string const & fmt,
string const to_base = removeExtension(to.absFilename());
string const to_extension = getExtension(to.absFilename());
vector<string> const files = dirList(FileName(path),
vector<FileName> const files = dirList(FileName(path),
getExtension(from.absFilename()));
for (vector<string>::const_iterator it = files.begin();
it != files.end(); ++it)
if (prefixIs(*it, base)) {
string const from2 = path + *it;
string to2 = to_base + it->substr(base.length());
to2 = changeExtension(to2, to_extension);
for (vector<FileName>::const_iterator it = files.begin();
it != files.end(); ++it) {
string const from2 = it->absFilename();
string const file2 = onlyFilename(from2);
if (prefixIs(file2, base)) {
string const to2 = changeExtension(
to_base + file2.substr(base.length()),
to_extension);
lyxerr[Debug::FILES] << "moving " << from2
<< " to " << to2 << endl;
Mover const & mover = movers(fmt);
bool const moved = copy
? mover.copy(FileName(from2), FileName(to2))
: mover.rename(FileName(from2), FileName(to2));
? mover.copy(*it, FileName(to2))
: mover.rename(*it, FileName(to2));
if (!moved && no_errors) {
Alert::error(_("Cannot convert file"),
bformat(copy ?
_("Could not copy a temporary file from %1$s to %2$s.") :
_("Could not move a temporary file from %1$s to %2$s."),
from_ascii(from2), from_ascii(to2)));
from_utf8(from2), from_utf8(to2)));
no_errors = false;
}
}
}
return no_errors;
}

View File

@ -70,6 +70,13 @@ string const FileName::toFilesystemEncoding() const
}
FileName const FileName::fromFilesystemEncoding(string const & name)
{
QByteArray const encoded(name.c_str(), name.length());
return FileName(fromqstr(QFile::decodeName(encoded)));
}
bool operator==(FileName const & lhs, FileName const & rhs)
{
return lhs.absFilename() == rhs.absFilename();

View File

@ -46,6 +46,13 @@ public:
* Only use this for accessing the file, e.g. with an fstream.
*/
std::string const toFilesystemEncoding() const;
/**
* Get a FileName from \p name in the encoding used by the file system.
* Only use this for filenames you got directly from the file system,
* e.g. from reading a directory.
* \p name must have an absolute path.
*/
static FileName const fromFilesystemEncoding(std::string const & name);
protected:
/// The absolute file name.
/// The encoding is currently unspecified, anything else than ASCII

View File

@ -218,10 +218,10 @@ FileName const fileOpenSearch(string const & path, string const & name,
/// Returns a vector of all files in directory dir having extension ext.
vector<string> const dirList(FileName const & dir, string const & ext)
vector<FileName> const dirList(FileName const & dir, string const & ext)
{
// EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
vector<string> dirlist;
vector<FileName> dirlist;
string const encoded_dir = dir.toFilesystemEncoding();
if (!(fs::exists(encoded_dir) && fs::is_directory(encoded_dir))) {
@ -240,10 +240,9 @@ vector<string> const dirList(FileName const & dir, string const & ext)
fs::directory_iterator end;
for (; dit != end; ++dit) {
string const & fil = dit->leaf();
if (suffixIs(fil, extension)) {
// FIXME UNICODE: We need to convert from filesystem encoding to utf8
dirlist.push_back(fil);
}
if (suffixIs(fil, extension))
dirlist.push_back(FileName::fromFilesystemEncoding(
makeAbsPath(fil, encoded_dir)));
}
return dirlist;
}

View File

@ -73,7 +73,7 @@ FileName const fileSearch(std::string const & path,
search_mode mode = standard_mode);
/// Returns a vector of all files in directory dir having extension ext.
std::vector<std::string> const dirList(FileName const & dir,
std::vector<FileName> const dirList(FileName const & dir,
std::string const & ext = std::string());
/** Is directory read only?