From df7b0a0a0e29b4b8285da704970869eca0422cd5 Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Mon, 27 Jul 2009 21:32:22 -0700 Subject: A workaround attempt to fix opening a file for writing then changing it to R/O later (happens with cp -a, etc) diff --git a/fusearchive.py b/fusearchive.py index 2ed69ed..13d56dd 100755 --- a/fusearchive.py +++ b/fusearchive.py @@ -8,7 +8,7 @@ # See the file COPYING. # -import os, sys, fcntl, fuse, sha, cPickle, gzip, errno, zipfile +import os, sys, fcntl, fuse, sha, cPickle, gzip, errno, zipfile, stat from fuse import Fuse import pdb @@ -257,8 +257,27 @@ class FuseArchiveStream: """This just allows switching out writer classes easily""" @staticmethod def open( path, mode = 'r' ): - return gzip.open( path, mode, gzip_compress_level ) - #return open( path, mode ) + # This was added to fix the case of copying a read-only file, cp + # will create the new file then it gets chmod or something but we + # don't keep an fh around to write to later, we open and close it + # every time we need to update the file info. We should keep an fh + # around from creation time and use that instead though and allow + # passing an fh here instead of a filename + if os.path.exists( path ): + st = os.stat( path ) + # Make it writable + os.chmod( path, stat.S_IWUSR ) + else: + st = None + + fh = gzip.open( path, mode, gzip_compress_level ) + + if st: + # Reset permissions + os.chmod( path, st.st_mode ) + + #fh = open( path, mode ) + return fh class FuseArchiveSerializer: """This lets us experiment with different main file serializers""" -- cgit v0.10.2