Преглед на файлове

Removed utf8ToNative from log message and exception message.

Tatsuhiro Tsujikawa преди 14 години
родител
ревизия
02307cee0a

+ 6 - 6
src/AbstractDiskWriter.cc

@@ -103,7 +103,7 @@ void AbstractDiskWriter::openExistingFile(uint64_t totalLength)
     throw DL_ABORT_EX3
       (errNum,
        fmt(EX_FILE_OPEN,
-           utf8ToNative(filename_).c_str(),
+           filename_.c_str(),
            util::safeStrerror(errNum).c_str()),
        error_code::FILE_OPEN_ERROR);
   }
@@ -122,7 +122,7 @@ void AbstractDiskWriter::createFile(int addFlags)
     throw DL_ABORT_EX3
       (errNum,
        fmt(EX_FILE_OPEN,
-           utf8ToNative(filename_).c_str(),
+           filename_.c_str(),
            util::safeStrerror(errNum).c_str()),
        error_code::FILE_CREATE_ERROR);
   }  
@@ -154,7 +154,7 @@ void AbstractDiskWriter::seek(off_t offset)
   if(a2lseek(fd_, offset, SEEK_SET) == (off_t)-1) {
     int errNum = errno;
     throw DL_ABORT_EX2(fmt(EX_FILE_SEEK,
-                           utf8ToNative(filename_).c_str(),
+                           filename_.c_str(),
                            util::safeStrerror(errNum).c_str()),
                        error_code::FILE_IO_ERROR);
   }
@@ -171,14 +171,14 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t
       throw DOWNLOAD_FAILURE_EXCEPTION3
         (errNum,
          fmt(EX_FILE_WRITE,
-             utf8ToNative(filename_).c_str(),
+             filename_.c_str(),
              util::safeStrerror(errNum).c_str()),
          error_code::NOT_ENOUGH_DISK_SPACE);
     } else {
       throw DL_ABORT_EX3
         (errNum,
          fmt(EX_FILE_WRITE,
-             utf8ToNative(filename_).c_str(),
+             filename_.c_str(),
              util::safeStrerror(errNum).c_str()),
          error_code::FILE_IO_ERROR);
     }
@@ -194,7 +194,7 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offs
     throw DL_ABORT_EX3
       (errNum,
        fmt(EX_FILE_READ,
-           utf8ToNative(filename_).c_str(),
+           filename_.c_str(),
            util::safeStrerror(errNum).c_str()),
        error_code::FILE_IO_ERROR);
   }

+ 1 - 1
src/BtDependency.cc

@@ -135,7 +135,7 @@ bool BtDependency::resolve()
           if(d == ctxFilesEnd) {
             throw DL_ABORT_EX
               (fmt("No entry %s in torrent file",
-                   utf8ToNative((*s)->getOriginalName()).c_str()));
+                   (*s)->getOriginalName().c_str()));
           }
           copyValues(*d, *s);
         }

+ 1 - 1
src/BtPostDownloadHandler.cc

@@ -69,7 +69,7 @@ void BtPostDownloadHandler::getNextRequestGroups
  RequestGroup* requestGroup)
 {
   A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
-                  utf8ToNative(requestGroup->getFirstFilePath()).c_str()));
+                  requestGroup->getFirstFilePath().c_str()));
   std::string content;
   try {
     requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();

+ 3 - 6
src/CheckIntegrityCommand.cc

@@ -73,8 +73,7 @@ bool CheckIntegrityCommand::executeInternal()
     if(getRequestGroup()->downloadFinished()) {
       A2_LOG_NOTICE
         (fmt(MSG_VERIFICATION_SUCCESSFUL,
-             utf8ToNative(getRequestGroup()->getDownloadContext()
-                          ->getBasePath()).c_str()));
+             getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
       std::vector<Command*>* commands = new std::vector<Command*>();
       auto_delete_container<std::vector<Command*> > commandsDel(commands);
       entry_->onDownloadFinished(*commands, getDownloadEngine());
@@ -83,8 +82,7 @@ bool CheckIntegrityCommand::executeInternal()
     } else {
       A2_LOG_ERROR
         (fmt(MSG_VERIFICATION_FAILED,
-             utf8ToNative(getRequestGroup()->getDownloadContext()
-                          ->getBasePath()).c_str()));
+             getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
       std::vector<Command*>* commands = new std::vector<Command*>();
       auto_delete_container<std::vector<Command*> > commandsDel(commands);
       entry_->onDownloadIncomplete(*commands, getDownloadEngine());
@@ -108,8 +106,7 @@ bool CheckIntegrityCommand::handleException(Exception& e)
   A2_LOG_ERROR
     (fmt(MSG_DOWNLOAD_NOT_COMPLETE,
          getCuid(),
-         utf8ToNative(getRequestGroup()->getDownloadContext()
-                      ->getBasePath()).c_str()));
+         getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
   return true;
 }
 

+ 7 - 12
src/CookieStorage.cc

@@ -341,8 +341,7 @@ bool CookieStorage::load(const std::string& filename, time_t now)
   {
     BufferedFile fp(filename, BufferedFile::READ);
     if(!fp) {
-      A2_LOG_ERROR(fmt("Failed to open cookie file %s",
-                     utf8ToNative(filename).c_str()));
+      A2_LOG_ERROR(fmt("Failed to open cookie file %s", filename.c_str()));
       return false;
     }
     headlen = fp.read(header, sizeof(header));
@@ -372,8 +371,7 @@ bool CookieStorage::load(const std::string& filename, time_t now)
     }
     return true;
   } catch(RecoverableException& e) {
-    A2_LOG_ERROR(fmt("Failed to load cookies from %s",
-                     utf8ToNative(filename).c_str()));
+    A2_LOG_ERROR(fmt("Failed to load cookies from %s", filename.c_str()));
     return false;
   }
 }
@@ -384,21 +382,18 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
   {
     BufferedFile fp(tempfilename, BufferedFile::WRITE);
     if(!fp) {
-      A2_LOG_ERROR(fmt("Cannot create cookie file %s",
-                       utf8ToNative(filename).c_str()));
+      A2_LOG_ERROR(fmt("Cannot create cookie file %s", filename.c_str()));
       return false;
     }
     for(std::deque<DomainEntry>::const_iterator i = domains_.begin(),
           eoi = domains_.end(); i != eoi; ++i) {
       if(!(*i).writeCookie(fp)) {
-        A2_LOG_ERROR(fmt("Failed to save cookies to %s",
-                         utf8ToNative(filename).c_str()));
+        A2_LOG_ERROR(fmt("Failed to save cookies to %s", filename.c_str()));
         return false;
       }
     }
     if(fp.close() == EOF) {
-      A2_LOG_ERROR(fmt("Failed to save cookies to %s",
-                       utf8ToNative(filename).c_str()));
+      A2_LOG_ERROR(fmt("Failed to save cookies to %s", filename.c_str()));
       return false;
     }  
   }
@@ -406,8 +401,8 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
     return true;
   } else {
     A2_LOG_ERROR(fmt("Could not rename file %s as %s",
-                     utf8ToNative(tempfilename).c_str(),
-                     utf8ToNative(filename).c_str()));
+                     tempfilename.c_str(),
+                     filename.c_str()));
     return false;
   }
 }

+ 3 - 3
src/DHTRoutingTableDeserializer.cc

@@ -76,11 +76,11 @@ void readBytes(BufferedFile& fp,
 void DHTRoutingTableDeserializer::deserialize(const std::string& filename)
 {
   A2_LOG_INFO(fmt("Loading DHT routing table from %s.",
-                  utf8ToNative(filename).c_str()));
+                  filename.c_str()));
   BufferedFile fp(filename, BufferedFile::READ);
   if(!fp) {
     throw DL_ABORT_EX(fmt("Failed to load DHT routing table from %s",
-                          utf8ToNative(filename).c_str()));
+                          filename.c_str()));
   }
   char header[8];
   memset(header, 0, sizeof(header));
@@ -122,7 +122,7 @@ void DHTRoutingTableDeserializer::deserialize(const std::string& filename)
   } else {
     throw DL_ABORT_EX
       (fmt("Failed to load DHT routing table from %s. cause:%s",
-           utf8ToNative(filename).c_str(),
+           filename.c_str(),
            "bad header"));
   }
   

+ 5 - 6
src/DHTRoutingTableSerializer.cc

@@ -72,18 +72,17 @@ void DHTRoutingTableSerializer::setNodes
 #define WRITE_CHECK(fp, ptr, count)                                     \
   if(fp.write((ptr), (count)) != (count)) {                             \
     throw DL_ABORT_EX(fmt("Failed to save DHT routing table to %s.",    \
-                          utf8ToNative(filename).c_str()));             \
+                          filename.c_str()));                           \
   }
 
 void DHTRoutingTableSerializer::serialize(const std::string& filename)
 {
-  A2_LOG_INFO(fmt("Saving DHT routing table to %s.",
-                  utf8ToNative(filename).c_str()));
+  A2_LOG_INFO(fmt("Saving DHT routing table to %s.", filename.c_str()));
   std::string filenameTemp = filename+"__temp";
   BufferedFile fp(filenameTemp, BufferedFile::WRITE);
   if(!fp) {
     throw DL_ABORT_EX(fmt("Failed to save DHT routing table to %s.",
-                          utf8ToNative(filename).c_str()));
+                          filename.c_str()));
   }
   char header[8];
   memset(header, 0, sizeof(header));
@@ -146,11 +145,11 @@ void DHTRoutingTableSerializer::serialize(const std::string& filename)
   }
   if(fp.close() == EOF) {
     throw DL_ABORT_EX(fmt("Failed to save DHT routing table to %s.",
-                          utf8ToNative(filename).c_str()));
+                          filename.c_str()));
   }
   if(!File(filenameTemp).renameTo(filename)) {
     throw DL_ABORT_EX(fmt("Failed to save DHT routing table to %s.",
-                          utf8ToNative(filename).c_str()));
+                          filename.c_str()));
   }
   A2_LOG_INFO("DHT routing table was saved successfully");
 }

+ 16 - 28
src/DefaultBtProgressInfoFile.cc

@@ -104,20 +104,18 @@ bool DefaultBtProgressInfoFile::isTorrentDownload()
 
 #define WRITE_CHECK(fp, ptr, count)                                     \
   if(fp.write((ptr), (count)) != (count)) {                             \
-    throw DL_ABORT_EX                                                   \
-      (fmt(EX_SEGMENT_FILE_WRITE, utf8ToNative(filename_).c_str()));    \
+    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));   \
   }
 
 // Since version 0001, Integers are saved in binary form, network byte order.
 void DefaultBtProgressInfoFile::save()
 {
-  A2_LOG_INFO(fmt(MSG_SAVING_SEGMENT_FILE, utf8ToNative(filename_).c_str()));
+  A2_LOG_INFO(fmt(MSG_SAVING_SEGMENT_FILE, filename_.c_str()));
   std::string filenameTemp = filename_+"__temp";
   {
     BufferedFile fp(filenameTemp, BufferedFile::WRITE);
     if(!fp) {
-      throw DL_ABORT_EX
-        (fmt(EX_SEGMENT_FILE_WRITE, utf8ToNative(filename_).c_str()));
+      throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));
     }
 #ifdef ENABLE_BITTORRENT
     bool torrentDownload = isTorrentDownload();
@@ -193,21 +191,18 @@ void DefaultBtProgressInfoFile::save()
       WRITE_CHECK(fp, (*itr)->getBitfield(), (*itr)->getBitfieldLength());
     }
     if(fp.close() == EOF) {
-      throw DL_ABORT_EX
-        (fmt(EX_SEGMENT_FILE_WRITE, utf8ToNative(filename_).c_str()));
+      throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));
     }
     A2_LOG_INFO(MSG_SAVED_SEGMENT_FILE);
   }
   if(!File(filenameTemp).renameTo(filename_)) {
-    throw DL_ABORT_EX
-      (fmt(EX_SEGMENT_FILE_WRITE, utf8ToNative(filename_).c_str()));
+    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_WRITE, filename_.c_str()));
   }
 }
 
-#define READ_CHECK(fp, ptr, count)                              \
-  if(fp.read((ptr), (count)) != (count)) {                      \
-    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ,                 \
-                          utf8ToNative(filename_).c_str()));    \
+#define READ_CHECK(fp, ptr, count)                                      \
+  if(fp.read((ptr), (count)) != (count)) {                              \
+    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ, filename_.c_str()));    \
   }
 
 // It is assumed that integers are saved as:
@@ -215,11 +210,10 @@ void DefaultBtProgressInfoFile::save()
 // 2) network byte order if version == 0001
 void DefaultBtProgressInfoFile::load() 
 {
-  A2_LOG_INFO(fmt(MSG_LOADING_SEGMENT_FILE, utf8ToNative(filename_).c_str()));
+  A2_LOG_INFO(fmt(MSG_LOADING_SEGMENT_FILE, filename_.c_str()));
   BufferedFile fp(filename_, BufferedFile::READ);
   if(!fp) {
-    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ,
-                          utf8ToNative(filename_).c_str()));
+    throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ, filename_.c_str()));
   }
   unsigned char versionBuf[2];
   READ_CHECK(fp, versionBuf, sizeof(versionBuf));
@@ -231,8 +225,7 @@ void DefaultBtProgressInfoFile::load()
     version = 1;
   } else {
     throw DL_ABORT_EX
-      (fmt("Unsupported ctrl file version: %s",
-           versionHex.c_str()));
+      (fmt("Unsupported ctrl file version: %s", versionHex.c_str()));
   }
   unsigned char extension[4];
   READ_CHECK(fp, extension, sizeof(extension));
@@ -249,8 +242,7 @@ void DefaultBtProgressInfoFile::load()
   }
   if((infoHashLength < 0) ||
      ((infoHashLength == 0) && infoHashCheckEnabled)) {
-    throw DL_ABORT_EX
-      (fmt("Invalid info hash length: %d", infoHashLength));
+    throw DL_ABORT_EX(fmt("Invalid info hash length: %d", infoHashLength));
   }
   if(infoHashLength > 0) {
     array_ptr<unsigned char> savedInfoHash(new unsigned char[infoHashLength]);
@@ -333,8 +325,7 @@ void DefaultBtProgressInfoFile::load()
         index = ntohl(index);
       }
       if(!(index < dctx_->getNumPieces())) {
-        throw DL_ABORT_EX
-          (fmt("piece index out of range: %u", index));
+        throw DL_ABORT_EX(fmt("piece index out of range: %u", index));
       }
       uint32_t length;
       READ_CHECK(fp, &length, sizeof(length));
@@ -342,8 +333,7 @@ void DefaultBtProgressInfoFile::load()
         length = ntohl(length);
       }
       if(!(length <=dctx_->getPieceLength())) {
-        throw DL_ABORT_EX
-          (fmt("piece length out of range: %u", length));
+        throw DL_ABORT_EX(fmt("piece length out of range: %u", length));
       }
       SharedHandle<Piece> piece(new Piece(index, length));
       uint32_t bitfieldLength;
@@ -408,12 +398,10 @@ bool DefaultBtProgressInfoFile::exists()
 {
   File f(filename_);
   if(f.isFile()) {
-    A2_LOG_INFO(fmt(MSG_SEGMENT_FILE_EXISTS,
-                    utf8ToNative(filename_).c_str()));
+    A2_LOG_INFO(fmt(MSG_SEGMENT_FILE_EXISTS, filename_.c_str()));
     return true;
   } else {
-    A2_LOG_INFO(fmt(MSG_SEGMENT_FILE_DOES_NOT_EXIST,
-                    utf8ToNative(filename_).c_str()));
+    A2_LOG_INFO(fmt(MSG_SEGMENT_FILE_DOES_NOT_EXIST, filename_.c_str()));
     return false;
   }
 }

+ 3 - 4
src/File.cc

@@ -148,14 +148,13 @@ bool File::mkdirs() {
     }
 #endif // __MINGW32__
     std::string dir = std::string(begin, j);
-    A2_LOG_DEBUG(fmt("Making directory %s", utf8ToNative(dir).c_str()));
+    A2_LOG_DEBUG(fmt("Making directory %s", dir.c_str()));
     if(File(dir).isDir()) {
-      A2_LOG_DEBUG(fmt("%s exists and is a directory.",
-                       utf8ToNative(dir).c_str()));
+      A2_LOG_DEBUG(fmt("%s exists and is a directory.", dir.c_str()));
       continue;
     }
     if(a2mkdir(utf8ToWChar(dir).c_str(), DIR_OPEN_MODE) == -1) {
-      A2_LOG_DEBUG(fmt("Failed to create %s", utf8ToNative(dir).c_str()));
+      A2_LOG_DEBUG(fmt("Failed to create %s", dir.c_str()));
       return false;
     }
   }

+ 1 - 2
src/FileAllocationCommand.cc

@@ -96,8 +96,7 @@ bool FileAllocationCommand::handleException(Exception& e)
   A2_LOG_ERROR
     (fmt(MSG_DOWNLOAD_NOT_COMPLETE,
          getCuid(),
-         utf8ToNative(getRequestGroup()->getDownloadContext()
-                      ->getBasePath()).c_str()));
+         getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
   return true;
 }
 

+ 1 - 1
src/FileEntry.cc

@@ -355,7 +355,7 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
   }
   A2_LOG_DEBUG(fmt("Removed %lu duplicate hostname URIs for path=%s",
                    static_cast<unsigned long>(uris_.size()-newURIs.size()),
-                   utf8ToNative(getPath()).c_str()));
+                   getPath().c_str()));
   uris_.swap(newURIs);
 }
 

+ 2 - 2
src/FtpNegotiationCommand.cc

@@ -376,7 +376,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
      isSameFileBeingDownloaded(getRequestGroup())) {
     throw DOWNLOAD_FAILURE_EXCEPTION2
       (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-           utf8ToNative(getRequestGroup()->getFirstFilePath()).c_str()),
+           getRequestGroup()->getFirstFilePath().c_str()),
        error_code::DUPLICATE_DOWNLOAD);
   }
   if(totalLength == 0) {
@@ -407,7 +407,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
       A2_LOG_NOTICE
         (fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
              util::itos(getRequestGroup()->getGID()).c_str(),
-             utf8ToNative(getRequestGroup()->getFirstFilePath()).c_str()));
+             getRequestGroup()->getFirstFilePath().c_str()));
       poolConnection();
 
       return false;

+ 3 - 3
src/HttpResponseCommand.cc

@@ -189,7 +189,7 @@ bool HttpResponseCommand::executeInternal()
     A2_LOG_NOTICE
       (fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
            util::itos(getRequestGroup()->getGID()).c_str(),
-           utf8ToNative(getRequestGroup()->getFirstFilePath()).c_str()));
+           getRequestGroup()->getFirstFilePath().c_str()));
     poolConnection();
     getFileEntry()->poolRequest(getRequest());
     return true;
@@ -258,7 +258,7 @@ bool HttpResponseCommand::executeInternal()
        isSameFileBeingDownloaded(getRequestGroup())) {
       throw DOWNLOAD_FAILURE_EXCEPTION2
         (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-             utf8ToNative(getRequestGroup()->getFirstFilePath()).c_str()),
+             getRequestGroup()->getFirstFilePath().c_str()),
          error_code::DUPLICATE_DOWNLOAD);
     }
     // update last modified time
@@ -442,7 +442,7 @@ bool HttpResponseCommand::handleOtherEncoding
     A2_LOG_NOTICE
       (fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
            util::itos(getRequestGroup()->getGID()).c_str(),
-           utf8ToNative(getRequestGroup()->getFirstFilePath()).c_str()));
+           getRequestGroup()->getFirstFilePath().c_str()));
     poolConnection();
     return true;
   }

+ 1 - 1
src/IteratableChunkChecksumValidator.cc

@@ -143,7 +143,7 @@ std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length
                                                          curoffset);
     if(r == 0 || r < static_cast<size_t>(woffset)) {
       throw DL_ABORT_EX
-        (fmt(EX_FILE_READ, utf8ToNative(dctx_->getBasePath()).c_str(),
+        (fmt(EX_FILE_READ, dctx_->getBasePath().c_str(),
              "data is too short"));
     }
     size_t wlength;

+ 1 - 1
src/Logger.cc

@@ -77,7 +77,7 @@ void Logger::openFile(const std::string& filename)
   closeFile();
   fpp_ = new BufferedFile(filename, BufferedFile::APPEND);
   if(!fpp_) {
-    throw DL_ABORT_EX(fmt(EX_FILE_OPEN, utf8ToNative(filename).c_str(), "n/a"));
+    throw DL_ABORT_EX(fmt(EX_FILE_OPEN, filename.c_str(), "n/a"));
   }
 }
 

+ 4 - 7
src/Metalink2RequestGroup.cc

@@ -197,8 +197,7 @@ Metalink2RequestGroup::createRequestGroup
         entryGroups.begin(), eoi = entryGroups.end(); itr != eoi; ++itr) {
     const std::string& metaurl = (*itr).first;
     const std::vector<SharedHandle<MetalinkEntry> >& mes = (*itr).second;
-    A2_LOG_INFO(fmt("Processing metaurl group metaurl=%s",
-                    utf8ToNative(metaurl).c_str()));
+    A2_LOG_INFO(fmt("Processing metaurl group metaurl=%s", metaurl.c_str()));
 #ifdef ENABLE_BITTORRENT
     SharedHandle<RequestGroup> torrentRg;
     if(!metaurl.empty()) {
@@ -234,8 +233,7 @@ Metalink2RequestGroup::createRequestGroup
     SharedHandle<DownloadContext> dctx;
     if(mes.size() == 1) {
       SharedHandle<MetalinkEntry> entry = mes[0];
-      A2_LOG_INFO(fmt(MSG_METALINK_QUEUEING,
-                      utf8ToNative(entry->getPath()).c_str()));
+      A2_LOG_INFO(fmt(MSG_METALINK_QUEUEING, entry->getPath().c_str()));
       entry->reorderResourcesByPriority();
       std::vector<std::string> uris;
       std::for_each(entry->resources.begin(), entry->resources.end(),
@@ -289,9 +287,8 @@ Metalink2RequestGroup::createRequestGroup
       for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
             mes.begin(), eoi = mes.end(); i != eoi; ++i) {
         A2_LOG_INFO(fmt("Metalink: Queueing %s for download as a member.",
-                        utf8ToNative((*i)->getPath()).c_str()));
-        A2_LOG_DEBUG(fmt("originalName = %s",
-                         utf8ToNative((*i)->metaurls[0]->name).c_str()));
+                        (*i)->getPath().c_str()));
+        A2_LOG_DEBUG(fmt("originalName = %s", (*i)->metaurls[0]->name.c_str()));
         (*i)->reorderResourcesByPriority();
         std::vector<std::string> uris;
         std::for_each((*i)->resources.begin(), (*i)->resources.end(),

+ 1 - 1
src/MetalinkPostDownloadHandler.cc

@@ -97,7 +97,7 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
  RequestGroup* requestGroup)
 {
   A2_LOG_DEBUG(fmt("Generating RequestGroups for Metalink file %s",
-                   utf8ToNative(requestGroup->getFirstFilePath()).c_str()));
+                   requestGroup->getFirstFilePath().c_str()));
   SharedHandle<DiskAdaptor> diskAdaptor =
     requestGroup->getPieceStorage()->getDiskAdaptor();
   try {

+ 4 - 4
src/MultiDiskAdaptor.cc

@@ -187,7 +187,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
           pieceLength_*pieceLength_;
         A2_LOG_DEBUG(fmt("Checking adjacent backward file to %s"
                          " whose lastPieceStartOffset+pieceLength_=%lld",
-                         utf8ToNative(fileEntry->getPath()).c_str(),
+                         fileEntry->getPath().c_str(),
                          static_cast<long long int>
                          (lastPieceStartOffset+pieceLength_)));
         ++itr;
@@ -198,14 +198,14 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
                (*itr)->getFileEntry()->getLength() == 0); ++itr) {
           A2_LOG_DEBUG
             (fmt("file=%s, offset=%lld",
-                 utf8ToNative((*itr)->getFileEntry()->getPath()).c_str(),
+                 (*itr)->getFileEntry()->getPath().c_str(),
                  static_cast<long long int>
                  ((*itr)->getFileEntry()->getOffset())));
           if((*itr)->getFileEntry()->getOffset() <
              static_cast<off_t>(lastPieceStartOffset+pieceLength_)) {
             A2_LOG_DEBUG
               (fmt("%s needs diskwriter",
-                   utf8ToNative((*itr)->getFileEntry()->getPath()).c_str()));
+                   (*itr)->getFileEntry()->getPath().c_str()));
             dwreq[(*itr)->getFileEntry()->getPath()] = true;
           } else {
             break;
@@ -226,7 +226,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
        dwreq.find((*i)->getFileEntry()->getPath()) != dwreq.end() ||
        (*i)->fileExists()) {
       A2_LOG_DEBUG(fmt("Creating DiskWriter for filename=%s",
-                       utf8ToNative((*i)->getFilePath()).c_str()));
+                       (*i)->getFilePath().c_str()));
       (*i)->setDiskWriter(dwFactory.newDiskWriter((*i)->getFilePath()));
       if(readOnly_) {
         (*i)->getDiskWriter()->enableReadOnly();

+ 1 - 1
src/Netrc.cc

@@ -139,7 +139,7 @@ void Netrc::parse(const std::string& path)
   authenticators_.clear();
   BufferedFile fp(path, BufferedFile::READ);
   if(!fp) {
-    throw DL_ABORT_EX(fmt("Cannot open file: %s", utf8ToNative(path).c_str()));
+    throw DL_ABORT_EX(fmt("Cannot open file: %s", path.c_str()));
   }
   enum STATE {
     GET_TOKEN,

+ 1 - 2
src/NsCookieParser.cc

@@ -98,8 +98,7 @@ std::vector<Cookie> NsCookieParser::parse
 {
   BufferedFile fp(filename, BufferedFile::READ);
   if(!fp) {
-    throw DL_ABORT_EX(fmt("Failed to open file %s",
-                          utf8ToNative(filename).c_str()));
+    throw DL_ABORT_EX(fmt("Failed to open file %s", filename.c_str()));
   }
   std::vector<Cookie> cookies;
   char buf[8192];

+ 14 - 17
src/RequestGroup.cc

@@ -249,7 +249,7 @@ SharedHandle<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry()
           A2_LOG_NOTICE
             (fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
                  util::itos(gid_).c_str(),
-                 utf8ToNative(downloadContext_->getBasePath()).c_str()));
+                 downloadContext_->getBasePath().c_str()));
         }
     } else {
       checkEntry.reset(new StreamCheckIntegrityEntry(this));
@@ -271,7 +271,7 @@ SharedHandle<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry()
         A2_LOG_NOTICE
           (fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
                util::itos(gid_).c_str(),
-               utf8ToNative(downloadContext_->getBasePath()).c_str()));
+               downloadContext_->getBasePath().c_str()));
       }
   } else {
     loadAndOpenFile(infoFile);
@@ -314,7 +314,7 @@ void RequestGroup::createInitialCommand
         if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
           throw DOWNLOAD_FAILURE_EXCEPTION2
             (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-                 utf8ToNative(downloadContext_->getBasePath()).c_str()),
+                 downloadContext_->getBasePath().c_str()),
              error_code::DUPLICATE_DOWNLOAD);
         }
         initPieceStorage();
@@ -421,7 +421,7 @@ void RequestGroup::createInitialCommand
             // TODO we need this->haltRequested = true?
             throw DOWNLOAD_FAILURE_EXCEPTION2
               (fmt(MSG_FILE_ALREADY_EXISTS,
-                   utf8ToNative(downloadContext_->getBasePath()).c_str()),
+                   downloadContext_->getBasePath().c_str()),
                error_code::FILE_ALREADY_EXISTS);
           } else {
             pieceStorage_->getDiskAdaptor()->openFile();
@@ -486,7 +486,7 @@ void RequestGroup::createInitialCommand
       if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
         throw DOWNLOAD_FAILURE_EXCEPTION2
           (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-               utf8ToNative(downloadContext_->getBasePath()).c_str()),
+               downloadContext_->getBasePath().c_str()),
            error_code::DUPLICATE_DOWNLOAD);
       }
       SharedHandle<BtProgressInfoFile> progressInfoFile
@@ -513,7 +513,7 @@ void RequestGroup::createInitialCommand
     if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
       throw DOWNLOAD_FAILURE_EXCEPTION2
         (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-             utf8ToNative(downloadContext_->getBasePath()).c_str()),
+             downloadContext_->getBasePath().c_str()),
          error_code::DUPLICATE_DOWNLOAD);
     }
     initPieceStorage();
@@ -537,7 +537,7 @@ void RequestGroup::createInitialCommand
           // TODO we need this->haltRequested = true?
           throw DOWNLOAD_FAILURE_EXCEPTION2
             (fmt(MSG_FILE_ALREADY_EXISTS,
-                 utf8ToNative(downloadContext_->getBasePath()).c_str()),
+                 downloadContext_->getBasePath().c_str()),
              error_code::FILE_ALREADY_EXISTS);
         } else {
           pieceStorage_->getDiskAdaptor()->openFile();
@@ -722,7 +722,7 @@ void RequestGroup::removeDefunctControlFile
     progressInfoFile->removeFile();
     A2_LOG_NOTICE(fmt(MSG_REMOVED_DEFUNCT_CONTROL_FILE,
                       progressInfoFile->getFilename().c_str(),
-                      utf8ToNative(downloadContext_->getBasePath()).c_str()));
+                      downloadContext_->getBasePath().c_str()));
   }
 }
 
@@ -771,18 +771,15 @@ void RequestGroup::shouldCancelDownloadForSafety()
   if(outfile.exists()) {
     if(option_->getAsBool(PREF_AUTO_FILE_RENAMING)) {
       if(tryAutoFileRenaming()) {
-        A2_LOG_NOTICE(fmt(MSG_FILE_RENAMED,
-                          utf8ToNative(getFirstFilePath()).c_str()));
+        A2_LOG_NOTICE(fmt(MSG_FILE_RENAMED, getFirstFilePath().c_str()));
       } else {
         throw DOWNLOAD_FAILURE_EXCEPTION2
-          (fmt("File renaming failed: %s",
-               utf8ToNative(getFirstFilePath()).c_str()),
+          (fmt("File renaming failed: %s", getFirstFilePath().c_str()),
            error_code::FILE_RENAMING_FAILED);
       }
     } else {
       throw DOWNLOAD_FAILURE_EXCEPTION2
-        (fmt(MSG_FILE_ALREADY_EXISTS,
-             utf8ToNative(getFirstFilePath()).c_str()),
+        (fmt(MSG_FILE_ALREADY_EXISTS, getFirstFilePath().c_str()),
          error_code::FILE_ALREADY_EXISTS);
     }
   }
@@ -1039,7 +1036,7 @@ void RequestGroup::releaseRuntimeResource(DownloadEngine* e)
 void RequestGroup::preDownloadProcessing()
 {
   A2_LOG_DEBUG(fmt("Finding PreDownloadHandler for path %s.",
-                   utf8ToNative(getFirstFilePath()).c_str()));
+                   getFirstFilePath().c_str()));
   try {
     for(std::vector<SharedHandle<PreDownloadHandler> >::const_iterator itr =
           preDownloadHandlers_.begin(), eoi = preDownloadHandlers_.end();
@@ -1061,7 +1058,7 @@ void RequestGroup::postDownloadProcessing
 (std::vector<SharedHandle<RequestGroup> >& groups)
 {
   A2_LOG_DEBUG(fmt("Finding PostDownloadHandler for path %s.",
-                   utf8ToNative(getFirstFilePath()).c_str()));
+                   getFirstFilePath().c_str()));
   try {
     for(std::vector<SharedHandle<PostDownloadHandler> >::const_iterator itr =
           postDownloadHandlers_.begin(), eoi = postDownloadHandlers_.end();
@@ -1203,7 +1200,7 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
 void RequestGroup::reportDownloadFinished()
 {
   A2_LOG_NOTICE(fmt(MSG_FILE_DOWNLOAD_COMPLETED,
-                    utf8ToNative(downloadContext_->getBasePath()).c_str()));
+                    downloadContext_->getBasePath().c_str()));
   uriSelector_->resetCounters();
 #ifdef ENABLE_BITTORRENT
   if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {

+ 1 - 2
src/RequestGroupMan.cc

@@ -343,8 +343,7 @@ public:
           A2_LOG_NOTICE
             (fmt("Download GID#%s not complete: %s",
                  util::itos(group->getGID()).c_str(),
-                 utf8ToNative(group->getDownloadContext()
-                              ->getBasePath()).c_str()));
+                 group->getDownloadContext()->getBasePath().c_str()));
           group->saveControlFile();
         }
       } catch(RecoverableException& ex) {

+ 1 - 1
src/SegmentMan.cc

@@ -471,7 +471,7 @@ size_t SegmentMan::countFreePieceFrom(size_t index) const
 void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
 {
   A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%s, length=%s",
-                   utf8ToNative(fileEntry->getPath()).c_str(),
+                   fileEntry->getPath().c_str(),
                    util::itos(fileEntry->getOffset()).c_str(),
                    util::uitos(fileEntry->getLength()).c_str()));
   ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());

+ 8 - 11
src/ServerStatMan.cc

@@ -94,7 +94,7 @@ bool ServerStatMan::save(const std::string& filename) const
     BufferedFile fp(tempfile, BufferedFile::WRITE);
     if(!fp) {
       A2_LOG_ERROR(fmt(MSG_OPENING_WRITABLE_SERVER_STAT_FILE_FAILED,
-                       utf8ToNative(filename).c_str()));
+                       filename.c_str()));
       return false;
     }
     for(std::deque<SharedHandle<ServerStat> >::const_iterator i =
@@ -103,22 +103,19 @@ bool ServerStatMan::save(const std::string& filename) const
       l += "\n";
       if(fp.write(l.data(), l.size()) != l.size()) {
         A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED,
-                         utf8ToNative(filename).c_str()));
+                         filename.c_str()));
       }
     }
     if(fp.close() == EOF) {
-      A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED,
-                       utf8ToNative(filename).c_str()));
+      A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED, filename.c_str()));
       return false;
     }
   }
   if(File(tempfile).renameTo(filename)) {
-    A2_LOG_NOTICE(fmt(MSG_SERVER_STAT_SAVED,
-                      utf8ToNative(filename).c_str()));
+    A2_LOG_NOTICE(fmt(MSG_SERVER_STAT_SAVED, filename.c_str()));
     return true;
   } else {
-    A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED,
-                     utf8ToNative(filename).c_str()));
+    A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED, filename.c_str()));
     return false;
   }
 }
@@ -137,7 +134,7 @@ bool ServerStatMan::load(const std::string& filename)
   BufferedFile fp(filename, BufferedFile::READ);
   if(!fp) {
     A2_LOG_ERROR(fmt(MSG_OPENING_READABLE_SERVER_STAT_FILE_FAILED,
-                     utf8ToNative(filename).c_str()));
+                     filename.c_str()));
     return false;
   }
   char buf[4096];
@@ -147,7 +144,7 @@ bool ServerStatMan::load(const std::string& filename)
         break;
       } else {
         A2_LOG_ERROR(fmt(MSG_READING_SERVER_STAT_FILE_FAILED,
-                         utf8ToNative(filename).c_str()));
+                         filename.c_str()));
         return false;
       }
     }
@@ -191,7 +188,7 @@ bool ServerStatMan::load(const std::string& filename)
       continue;
     }
   }
-  A2_LOG_NOTICE(fmt(MSG_SERVER_STAT_LOADED, utf8ToNative(filename).c_str()));
+  A2_LOG_NOTICE(fmt(MSG_SERVER_STAT_LOADED, filename.c_str()));
   return true;
 }
 

+ 2 - 2
src/util.cc

@@ -143,7 +143,7 @@ std::wstring utf8ToWChar(const std::string& src)
   }
 }
 
-std::string utf8ToNative(const std::string& src)
+std::string const std::string& src
 {
   std::wstring wsrc = utf8ToWChar(src);
   int len = wCharToAnsi(0, 0, wsrc);
@@ -1286,7 +1286,7 @@ void mkdirs(const std::string& dirpath)
     if(!dir.isDir()) {
       throw DL_ABORT_EX3
         (errNum,
-         fmt(EX_MAKE_DIR, utf8ToNative(dir.getPath()).c_str(),
+         fmt(EX_MAKE_DIR, dir.getPath().c_str(),
              safeStrerror(errNum).c_str()),
          error_code::DIR_CREATE_ERROR);
     }