summaryrefslogtreecommitdiffstats
path: root/Source/cmArchiveWrite.cxx
diff options
context:
space:
mode:
authorClinton Stimpson <clinton@elemtech.com>2014-06-12 12:46:40 (GMT)
committerBrad King <brad.king@kitware.com>2014-07-02 13:49:45 (GMT)
commit71c981a213a463d05b4bdc73dfb445c80ce2a476 (patch)
tree405e5066ef637cf3d8cd32879498e20014e58ac9 /Source/cmArchiveWrite.cxx
parent6b05e03de4353275d1e2e614150757397bd1f855 (diff)
downloadCMake-71c981a213a463d05b4bdc73dfb445c80ce2a476.zip
CMake-71c981a213a463d05b4bdc73dfb445c80ce2a476.tar.gz
CMake-71c981a213a463d05b4bdc73dfb445c80ce2a476.tar.bz2
Encoding: Fix potential encoding issues with libarchive on Windows.
Because the 8bit string encoding in libarchive can be different than the 8bit string encoding in CMake, change to call the wide version of libarchive functions. They are different if CMake is configured to use UTF-8 as the internal encoding. Create helper functions for some libarchive calls to use wstring internally on platforms supporting it.
Diffstat (limited to 'Source/cmArchiveWrite.cxx')
-rw-r--r--Source/cmArchiveWrite.cxx26
1 files changed, 24 insertions, 2 deletions
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index 58f7573..3b0ead5 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -25,6 +25,28 @@ static std::string cm_archive_error_string(struct archive* a)
}
//----------------------------------------------------------------------------
+static void cm_archive_entry_copy_pathname(struct archive_entry* e,
+ const std::string& dest)
+{
+#if cmsys_STL_HAS_WSTRING
+ archive_entry_copy_pathname_w(e, cmsys::Encoding::ToWide(dest).c_str());
+#else
+ archive_entry_copy_pathname(e, dest.c_str());
+#endif
+}
+
+//----------------------------------------------------------------------------
+static void cm_archive_entry_copy_sourcepath(struct archive_entry* e,
+ const std::string& file)
+{
+#if cmsys_STL_HAS_WSTRING
+ archive_entry_copy_sourcepath_w(e, cmsys::Encoding::ToWide(file).c_str());
+#else
+ archive_entry_copy_sourcepath(e, file.c_str());
+#endif
+}
+
+//----------------------------------------------------------------------------
class cmArchiveWrite::Entry
{
struct archive_entry* Object;
@@ -237,8 +259,8 @@ bool cmArchiveWrite::AddFile(const char* file,
std::cout << dest << "\n";
}
Entry e;
- archive_entry_copy_sourcepath(e, file);
- archive_entry_set_pathname(e, dest.c_str());
+ cm_archive_entry_copy_sourcepath(e, file);
+ cm_archive_entry_copy_pathname(e, dest);
if(archive_read_disk_entry_from_file(this->Disk, e, -1, 0) != ARCHIVE_OK)
{
this->Error = "archive_read_disk_entry_from_file: ";