Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/browser/shell_integration_linux.cc

Issue 614893004: Refactor AppendToFile and WriteFileDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/shell_integration_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #if defined(USE_GLIB) 9 #if defined(USE_GLIB)
10 #include <glib.h> 10 #include <glib.h>
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 int fd = openat(desktop_fd, shortcut_filename.value().c_str(), 157 int fd = openat(desktop_fd, shortcut_filename.value().c_str(),
158 O_CREAT | O_EXCL | O_WRONLY, 158 O_CREAT | O_EXCL | O_WRONLY,
159 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); 159 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
160 if (fd < 0) { 160 if (fd < 0) {
161 if (IGNORE_EINTR(close(desktop_fd)) < 0) 161 if (IGNORE_EINTR(close(desktop_fd)) < 0)
162 PLOG(ERROR) << "close"; 162 PLOG(ERROR) << "close";
163 return false; 163 return false;
164 } 164 }
165 165
166 ssize_t bytes_written = base::WriteFileDescriptor(fd, contents.data(), 166 if (!base::WriteFileDescriptor(fd, contents.c_str(), contents.size())) {
167 contents.length());
168 if (IGNORE_EINTR(close(fd)) < 0)
169 PLOG(ERROR) << "close";
170
171 if (bytes_written != static_cast<ssize_t>(contents.length())) {
172 // Delete the file. No shortuct is better than corrupted one. Use unlinkat 167 // Delete the file. No shortuct is better than corrupted one. Use unlinkat
173 // to make sure we're deleting the file in the directory we think we are. 168 // to make sure we're deleting the file in the directory we think we are.
174 // Even if an attacker manager to put something other at 169 // Even if an attacker manager to put something other at
175 // |shortcut_filename| we'll just undo his action. 170 // |shortcut_filename| we'll just undo his action.
176 unlinkat(desktop_fd, shortcut_filename.value().c_str(), 0); 171 unlinkat(desktop_fd, shortcut_filename.value().c_str(), 0);
177 } 172 }
178 173
174 if (IGNORE_EINTR(close(fd)) < 0)
175 PLOG(ERROR) << "close";
176
179 if (IGNORE_EINTR(close(desktop_fd)) < 0) 177 if (IGNORE_EINTR(close(desktop_fd)) < 0)
180 PLOG(ERROR) << "close"; 178 PLOG(ERROR) << "close";
181 179
182 return true; 180 return true;
183 } 181 }
184 182
185 void DeleteShortcutOnDesktop(const base::FilePath& shortcut_filename) { 183 void DeleteShortcutOnDesktop(const base::FilePath& shortcut_filename) {
186 base::FilePath desktop_path; 184 base::FilePath desktop_path;
187 if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) 185 if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path))
188 base::DeleteFile(desktop_path.Append(shortcut_filename), false); 186 base::DeleteFile(desktop_path.Append(shortcut_filename), false);
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 for (std::vector<base::FilePath>::const_iterator it = 1072 for (std::vector<base::FilePath>::const_iterator it =
1075 shortcut_filenames_app_menu.begin(); 1073 shortcut_filenames_app_menu.begin();
1076 it != shortcut_filenames_app_menu.end(); ++it) { 1074 it != shortcut_filenames_app_menu.end(); ++it) {
1077 DeleteShortcutInApplicationsMenu(*it, 1075 DeleteShortcutInApplicationsMenu(*it,
1078 base::FilePath(kDirectoryFilename)); 1076 base::FilePath(kDirectoryFilename));
1079 } 1077 }
1080 } 1078 }
1081 } 1079 }
1082 1080
1083 } // namespace shell_integration_linux 1081 } // namespace shell_integration_linux
OLDNEW
« no previous file with comments | « chrome/browser/net/net_log_temp_file_unittest.cc ('k') | chromeos/process_proxy/process_output_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698