Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21015

Re: check if directory is writable in a portable way

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <skippy.hammond@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.036
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'attempting': 0.04; 'skip': 0.04; 'membership,': 0.07; 'files.': 0.09; '"owner"': 0.16; '"real"': 0.16; 'failure.': 0.16; 'from:name:mark hammond': 0.16; 'graceful': 0.16; 'group?': 0.16; 'received:192.168.0.9': 0.16; 'reply-to:addr:mhammond': 0.16; 'reply-to:addr:skippinet.com.au': 0.16; 'temp': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'later': 0.19; 'trying': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.26; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'can.': 0.30; 'message-id:@gmail.com': 0.31; 'quite': 0.31; 'app': 0.31; 'does': 0.32; 'actual': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'file': 0.34; 'something': 0.35; 'things': 0.35; 'received:209.85.160': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'received:192': 0.38; 'think': 0.38; 'should': 0.38; 'files': 0.39; 'received:209.85.160.46': 0.39; 'received:mail- pw0-f46.google.com': 0.39; 'received:209': 0.39; 'being': 0.40; 'header:Received:6': 0.61; 'your': 0.61; 'ever': 0.64; 'further,': 0.67; 'rights': 0.68; 'header:Reply-To:1': 0.70; 'care': 0.71; 'reply-to:no real name:2**0': 0.72; 'failure': 0.74; 'andrea': 0.84; 'elevation': 0.84; 'elevated': 0.91; 'virtue': 0.91; 'presumably': 0.93
Received-SPF pass (google.com: domain of skippy.hammond@gmail.com designates 10.68.211.38 as permitted sender) client-ip=10.68.211.38;
Authentication-Results mr.google.com; spf=pass (google.com: domain of skippy.hammond@gmail.com designates 10.68.211.38 as permitted sender) smtp.mail=skippy.hammond@gmail.com; dkim=pass header.i=skippy.hammond@gmail.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=hRrUbCX/hUmbedmlU6zuM4jPE/KRFMKUtg0fbMQvZz8=; b=rotpZhSuHzko6DmrT7wEs1cHZh8YG2CFXeGod03KMpL6cOAv7FVZEYbxrJ/OLmAy8v RzrzVnhpAfYlQZYwVoYaUKh+iasjjU5LoWxKs3u4xh6hhPNk/WliuPK3JNzY9bmojUzw YxE9sNEod19laQKb5LjqviA7O4wwsW5e+Q7Y0=
Date Wed, 29 Feb 2012 10:32:10 +1100
From Mark Hammond <skippy.hammond@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0a2) Gecko/20120226 Thunderbird/12.0a2
MIME-Version 1.0
To Andrea Crotti <andrea.crotti.0@gmail.com>
Subject Re: check if directory is writable in a portable way
References <4F4CA76B.5040408@gmail.com>
In-Reply-To <4F4CA76B.5040408@gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To mhammond@skippinet.com.au
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.270.1330471991.3037.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330471992 news.xs4all.nl 6874 [2001:888:2000:d::a6]:37632
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:21015

Show key headers only | View raw


On 28/02/2012 9:07 PM, Andrea Crotti wrote:
> How should I check if I can create files in a directory?

By trying to create them there :)  Presumably you want to know that so 
you can write something "real" - so just write that something real.

The problem gets quite hard when you consider things like elevation - 
your *user* may have rights to write to a directory but only when 
elevated - think writing into Program Files.  Further, this check can 
only ever be transient - what if you have the rights by virtue of a 
group membership, but tomorrow you are no longer in that group?  Or by 
virtue of being the "owner" of the directory but later losing the ownership?

The only reasonable way to check is to write to it, and you may as well 
skip attempting to write a temp file - just write what you care about 
and handle failure in the most graceful way you can.  This is what 
almost every app does - consider apps with a "save as" dialog - they 
never check the directory is writable, they just attempt the actual 
write and handle the failure.

Mark

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: check if directory is writable in a portable way Mark Hammond <skippy.hammond@gmail.com> - 2012-02-29 10:32 +1100

csiph-web