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

Side by Side Diff: base/file_util_posix.cc

Issue 10756020: 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: Review fix 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, int* mode) {
461 base::ThreadRestrictions::AssertIOAllowed();
462 DCHECK(mode);
463
464 stat_wrapper_t file_info;
465 // Uses stat(), because on symbolic link, lstat() does not return valid
466 // permission bits in st_mode
467 if (CallStat(path.value().c_str(), &file_info) != 0)
468 return false;
469
470 *mode = file_info.st_mode & FILE_PERMISSION_MASK;
471 return true;
472 }
473
474 bool SetPosixFilePermissions(const FilePath& path,
475 int mode) {
476 base::ThreadRestrictions::AssertIOAllowed();
477 DCHECK((mode & ~FILE_PERMISSION_MASK) == 0);
478
479 stat_wrapper_t stat_buf;
480 if (CallStat(path.value().c_str(), &stat_buf) != 0)
481 return false;
482
satorux1 2012/07/10 06:57:17 might want to add // Clear the existing permissio
yoshiki 2012/07/10 18:51:36 Done.
483 mode_t updated_mode_bits = stat_buf.st_mode & ~FILE_PERMISSION_MASK;
484 updated_mode_bits |= mode & FILE_PERMISSION_MASK;
485
486 if (HANDLE_EINTR(chmod(path.value().c_str(), updated_mode_bits)) != 0)
487 return false;
488
489 return true;
490 }
491
460 // Creates and opens a temporary file in |directory|, returning the 492 // Creates and opens a temporary file in |directory|, returning the
461 // file descriptor. |path| is set to the temporary file path. 493 // file descriptor. |path| is set to the temporary file path.
462 // This function does NOT unlink() the file. 494 // This function does NOT unlink() the file.
463 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { 495 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
464 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp(). 496 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp().
465 *path = directory.Append(TempFileName()); 497 *path = directory.Append(TempFileName());
466 const std::string& tmpdir_string = path->value(); 498 const std::string& tmpdir_string = path->value();
467 // this should be OK since mkstemp just replaces characters in place 499 // this should be OK since mkstemp just replaces characters in place
468 char* buffer = const_cast<char*>(tmpdir_string.c_str()); 500 char* buffer = const_cast<char*>(tmpdir_string.c_str());
469 501
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 1147
1116 allowed_group_ids.insert(group_record->gr_gid); 1148 allowed_group_ids.insert(group_record->gr_gid);
1117 } 1149 }
1118 1150
1119 return VerifyPathControlledByUser( 1151 return VerifyPathControlledByUser(
1120 kFileSystemRoot, path, kRootUid, allowed_group_ids); 1152 kFileSystemRoot, path, kRootUid, allowed_group_ids);
1121 } 1153 }
1122 #endif // defined(OS_MACOSX) 1154 #endif // defined(OS_MACOSX)
1123 1155
1124 } // namespace file_util 1156 } // namespace file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698