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

Side by Side Diff: base/file_util_posix.cc

Issue 10696069: Add the methods to change and get a posix file permission to file_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove gdata part from this chengelist. Created 8 years, 5 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 | Annotate | Revision Log
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 "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 if (count <= 0) { 451 if (count <= 0) {
452 target_path->clear(); 452 target_path->clear();
453 return false; 453 return false;
454 } 454 }
455 455
456 *target_path = FilePath(FilePath::StringType(buf, count)); 456 *target_path = FilePath(FilePath::StringType(buf, count));
457 return true; 457 return true;
458 } 458 }
459 459
460 bool GetPosixFilePermissions(const FilePath& path, mode_t* mode) {
461 base::ThreadRestrictions::AssertIOAllowed();
462 DCHECK(mode);
463
464 stat_wrapper_t file_info;
465 if (CallStat(path.value().c_str(), &file_info) != 0)
satorux1 2012/07/03 06:16:55 i think there is a reason not to use lstat here. p
yoshiki 2012/07/04 07:57:57 Done.
466 return false;
467
468 *mode = file_info.st_mode;
469 return true;
470 }
471
472 bool ChangePosixFilePermissions(const FilePath& path,
473 mode_t mode_bits_to_set,
474 mode_t mode_bits_to_clear) {
475 base::ThreadRestrictions::AssertIOAllowed();
476 DCHECK(!(mode_bits_to_set & mode_bits_to_clear))
477 << "Can't set and clear the same bits.";
478
479 stat_wrapper_t stat_buf;
480 if (CallLstat(path.value().c_str(), &stat_buf) != 0)
satorux1 2012/07/03 06:16:55 why lstat? it seems lstat on symbolic link is inva
satorux1 2012/07/03 06:22:36 invalid for permission bits
yoshiki 2012/07/04 07:57:57 Sorry, I made a mistake. On 2012/07/03 06:16:55,
481 return false;
482
483 mode_t updated_mode_bits = stat_buf.st_mode;
484 updated_mode_bits |= mode_bits_to_set;
485 updated_mode_bits &= ~mode_bits_to_clear;
486
487 if (chmod(path.value().c_str(), updated_mode_bits) != 0)
satorux1 2012/07/03 06:23:29 please use HANDLE_EINTR when you call a system cal
yoshiki 2012/07/04 07:57:57 Done.
488 return false;
489
490 return true;
491 }
492
460 // Creates and opens a temporary file in |directory|, returning the 493 // Creates and opens a temporary file in |directory|, returning the
461 // file descriptor. |path| is set to the temporary file path. 494 // file descriptor. |path| is set to the temporary file path.
462 // This function does NOT unlink() the file. 495 // This function does NOT unlink() the file.
463 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { 496 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
464 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp(). 497 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp().
465 *path = directory.Append(TempFileName()); 498 *path = directory.Append(TempFileName());
466 const std::string& tmpdir_string = path->value(); 499 const std::string& tmpdir_string = path->value();
467 // this should be OK since mkstemp just replaces characters in place 500 // this should be OK since mkstemp just replaces characters in place
468 char* buffer = const_cast<char*>(tmpdir_string.c_str()); 501 char* buffer = const_cast<char*>(tmpdir_string.c_str());
469 502
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 1148
1116 allowed_group_ids.insert(group_record->gr_gid); 1149 allowed_group_ids.insert(group_record->gr_gid);
1117 } 1150 }
1118 1151
1119 return VerifyPathControlledByUser( 1152 return VerifyPathControlledByUser(
1120 kFileSystemRoot, path, kRootUid, allowed_group_ids); 1153 kFileSystemRoot, path, kRootUid, allowed_group_ids);
1121 } 1154 }
1122 #endif // defined(OS_MACOSX) 1155 #endif // defined(OS_MACOSX)
1123 1156
1124 } // namespace file_util 1157 } // namespace file_util
OLDNEW
« base/file_util.h ('K') | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698