~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-17 14:54:20 UTC
  • mto: (4634.108.4 2.0)
  • mto: This revision was merged to the branch mainline in revision 4928.
  • Revision ID: john@arbash-meinel.com-20091217145420-5cmm4iqody73e5sm
Change to using os.open() allowing the users umask to handle perms.

So a user with 0007 will not create other-readable files in the export.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
               (ie.file_id, ie.kind))
79
79
    # The data returned here can be in any order, but we've already created all
80
80
    # the directories
 
81
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
81
82
    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
82
83
        if filtered:
83
84
            filters = tree._content_filter_stack(relpath)
84
85
            context = ContentFilterContext(relpath, tree, ie)
85
86
            chunks = filtered_output_bytes(chunks, filters, context)
86
87
        fullpath = osutils.pathjoin(dest, relpath)
87
 
        out = open(fullpath, 'wb')
 
88
        # We set the mode and let the umask sort out the file info
 
89
        mode = 0666
 
90
        if executable:
 
91
            mode = 0777
 
92
        out = os.fdopen(os.open(fullpath, flags, mode))
88
93
        try:
89
94
            out.writelines(chunks)
90
95
        finally:
91
96
            out.close()
92
 
        if executable:
93
 
            os.chmod(fullpath, 0755)