[llvm-commits] [llvm] r156591 - in /llvm/trunk: include/llvm/Support/FileSystem.h lib/Support/Unix/PathV2.inc lib/Support/Windows/PathV2.inc

Nick Kledzik kledzik at apple.com
Tue May 15 16:54:55 PDT 2012


I thought this FileSystem layer was supposed to abstract away OS details.  But this change puts the Unix permissions model right in the interface.  How is the new 'mode' parameter supposed to be implemented on Windows?

I've been working on linker support and also need to be able to (on Unix) to set the 'x' bit on created files.   But my thinking was to be more abstract.  In my patch, I added a new parameter "bool private_file=true".  When it is set,  on unix the open permissions is 0600, but when false, it is 0644.    I think the unique_file() function was originally meant for just temp files, hence the 0600 permissions.   The other part of my patch is a function to flip on the 'x' bit on any file.

-Nick

On May 10, 2012, at 5:07 PM, Eric Christopher wrote:
> Author: echristo
> Date: Thu May 10 19:07:44 2012
> New Revision: 156591
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=156591&view=rev
> Log:
> Allow unique_file to take a mode for file permissions, but default
> to user only read/write.
> 
> Part of rdar://11325849
> 
> Modified:
>    llvm/trunk/include/llvm/Support/FileSystem.h
>    llvm/trunk/lib/Support/Unix/PathV2.inc
>    llvm/trunk/lib/Support/Windows/PathV2.inc
> 
> Modified: llvm/trunk/include/llvm/Support/FileSystem.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=156591&r1=156590&r2=156591&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/FileSystem.h (original)
> +++ llvm/trunk/include/llvm/Support/FileSystem.h Thu May 10 19:07:44 2012
> @@ -422,8 +422,8 @@
> /// @results errc::success if result_{fd,path} have been successfully set,
> ///          otherwise a platform specific error_code.
> error_code unique_file(const Twine &model, int &result_fd,
> -                             SmallVectorImpl<char> &result_path,
> -                             bool makeAbsolute = true);
> +                       SmallVectorImpl<char> &result_path,
> +                       bool makeAbsolute = true, unsigned mode = 0600);
> 
> /// @brief Canonicalize path.
> ///
> 
> Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=156591&r1=156590&r2=156591&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
> +++ llvm/trunk/lib/Support/Unix/PathV2.inc Thu May 10 19:07:44 2012
> @@ -347,9 +347,10 @@
>   return error_code::success();
> }
> 
> +// Since this is most often used for temporary files, mode defaults to 0600.
> error_code unique_file(const Twine &model, int &result_fd,
> -                             SmallVectorImpl<char> &result_path,
> -                             bool makeAbsolute) {
> +                       SmallVectorImpl<char> &result_path,
> +                       bool makeAbsolute, unsigned mode) {
>   SmallString<128> Model;
>   model.toVector(Model);
>   // Null terminate.
> @@ -379,7 +380,7 @@
> 
>   // Try to open + create the file.
> rety_open_create:
> -  int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
> +  int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);
>   if (RandomFD == -1) {
>     // If the file existed, try again, otherwise, error.
>     if (errno == errc::file_exists)
> 
> Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=156591&r1=156590&r2=156591&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
> +++ llvm/trunk/lib/Support/Windows/PathV2.inc Thu May 10 19:07:44 2012
> @@ -497,9 +497,11 @@
>   return error_code::success();
> }
> 
> +// FIXME: mode should be used here and default to user r/w only,
> +// it currently comes in as a UNIX mode.
> error_code unique_file(const Twine &model, int &result_fd,
> -                             SmallVectorImpl<char> &result_path,
> -                             bool makeAbsolute) {
> +                       SmallVectorImpl<char> &result_path,
> +                       bool makeAbsolute, unsigned mode) {
>   // Use result_path as temp storage.
>   result_path.set_size(0);
>   StringRef m = model.toStringRef(result_path);
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list