From: Cheng Zhao Date: Wed, 2 Dec 2015 03:04:47 +0000 (+0800) Subject: Don't call Move if there is no need to move X-Git-Tag: v0.35.3~13 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c3645e3f9532f71fea15dd5c6dad603954978afe;p=electron.git Don't call Move if there is no need to move --- diff --git a/atom/common/asar/scoped_temporary_file.cc b/atom/common/asar/scoped_temporary_file.cc index 2cc51991..14f2ba8e 100644 --- a/atom/common/asar/scoped_temporary_file.cc +++ b/atom/common/asar/scoped_temporary_file.cc @@ -28,23 +28,26 @@ ScopedTemporaryFile::~ScopedTemporaryFile() { } } -bool ScopedTemporaryFile::Init(const base::FilePath::StringType ext) { +bool ScopedTemporaryFile::Init(const base::FilePath::StringType& ext) { if (!path_.empty()) return true; base::ThreadRestrictions::ScopedAllowIO allow_io; - base::FilePath temporaryPath_; - if (!base::CreateTemporaryFile(&temporaryPath_)) { + base::FilePath temp_path; + if (!base::CreateTemporaryFile(&temp_path)) return false; - } - path_ = temporaryPath_.AddExtension(ext); - return base::Move(temporaryPath_, path_); + if (ext.empty()) + return true; + + // Keep the original extension. + path_ = temp_path.AddExtension(ext); + return base::Move(temp_path, path_); } bool ScopedTemporaryFile::InitFromFile(base::File* src, - const base::FilePath::StringType ext, + const base::FilePath::StringType& ext, uint64 offset, uint64 size) { if (!src->IsValid()) return false; diff --git a/atom/common/asar/scoped_temporary_file.h b/atom/common/asar/scoped_temporary_file.h index c0804a4e..23660a23 100644 --- a/atom/common/asar/scoped_temporary_file.h +++ b/atom/common/asar/scoped_temporary_file.h @@ -23,11 +23,11 @@ class ScopedTemporaryFile { virtual ~ScopedTemporaryFile(); // Init an empty temporary file with a certain extension. - bool Init(const base::FilePath::StringType ext); + bool Init(const base::FilePath::StringType& ext); // Init an temporary file and fill it with content of |path|. bool InitFromFile(base::File* src, - const base::FilePath::StringType ext, + const base::FilePath::StringType& ext, uint64 offset, uint64 size); base::FilePath path() const { return path_; }