You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by cm...@collab.net on 2002/11/13 16:26:04 UTC

apr_file_temp_dir()

This has been mentioned before -- at least by myself, perhaps by
others, too -- but the Subversion folks would *really* like to see APR
grow a gimme-a-temp-directory function.

The following is the code portion from Python2.2's tempfile module
whereby a list of places to try as valid temp directories is assembled:

    attempdirs = ['/tmp', '/var/tmp', '/usr/tmp', pwd]
    if os.name == 'nt':
        attempdirs.insert(0, 'C:\\TEMP')
        attempdirs.insert(0, '\\TEMP')
    elif os.name == 'mac':
        import macfs, MACFS
        try:
            refnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk,
                                             MACFS.kTemporaryFolderType, 1)
            dirname = macfs.FSSpec((refnum, dirid, '')).as_pathname()
            attempdirs.insert(0, dirname)
        except macfs.error:
            pass
    elif os.name == 'riscos':
        scrapdir = os.getenv('Wimp$ScrapDir')
        if scrapdir:
            attempdirs.insert(0, scrapdir)
    for envname in 'TMPDIR', 'TEMP', 'TMP':
        if os.environ.has_key(envname):
            attempdirs.insert(0, os.environ[envname])

Once the list is built, Python simply starts at the head of the list
(sorry, the "sequence") and checks each path until it finds one in
which it can successfully create, write to (the string "blat", not
that it matters), and remove a file.  If no valid directory exists in
the list, an exception is thrown and the caller is just out-of-luck.

I seem to recall that at one point or another, someone was looking
into the Windows side of this functionality (wrowe?).  If no one has
any objections, I'd like to try to implement the same algorithm that
Python uses in APR.  I don't know how os2 and netware fit into the
picture -- I'd need some guidance there.  

As for location and naming, perhaps apr_filepath_temp() would cause
the least disturbance (since all 4 OS-directories under file_io/ have
filepath.c files).

Thoughts?  

Volunteers to do this for me? :-)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: apr_file_temp_dir()

Posted by "William A. Rowe, Jr." <wr...@apache.org>.
At 01:16 PM 11/13/2002, Greg Hudson wrote:
>On Wed, 2002-11-13 at 11:26, cmpilato@collab.net wrote:
>> This has been mentioned before -- at least by myself, perhaps by
>> others, too -- but the Subversion folks would *really* like to see APR
>> grow a gimme-a-temp-directory function.
>
>Would gimme-a-temp-file be a better interface?  Like mkstemp(), but
>without the template argument?  (And maybe returning an apr_file_t *
>instead of a file descriptor.)

I'd like them both, actually.

Another thing to consider, that I'll step up and code, would be the
apr_filepath_list_*() functions for colon v.s. semicolon (mopping up 
quoted strings) PATH or whatnot processing.

The only question; would returning an apr_array_header_t from _split
and merging only apr_array_header_t's in the _merge flavor work
for everyone?  Or what would be a better interface?

Bill


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: apr_file_temp_dir()

Posted by "William A. Rowe, Jr." <wr...@apache.org>.
At 01:16 PM 11/13/2002, Greg Hudson wrote:
>On Wed, 2002-11-13 at 11:26, cmpilato@collab.net wrote:
>> This has been mentioned before -- at least by myself, perhaps by
>> others, too -- but the Subversion folks would *really* like to see APR
>> grow a gimme-a-temp-directory function.
>
>Would gimme-a-temp-file be a better interface?  Like mkstemp(), but
>without the template argument?  (And maybe returning an apr_file_t *
>instead of a file descriptor.)

I'd like them both, actually.

Another thing to consider, that I'll step up and code, would be the
apr_filepath_list_*() functions for colon v.s. semicolon (mopping up 
quoted strings) PATH or whatnot processing.

The only question; would returning an apr_array_header_t from _split
and merging only apr_array_header_t's in the _merge flavor work
for everyone?  Or what would be a better interface?

Bill


Re: apr_file_temp_dir()

Posted by Greg Hudson <gh...@MIT.EDU>.
On Wed, 2002-11-13 at 14:21, Philip Martin wrote:
> Suppose I want to create a temporary directory (quite a common
> technique to avoid certain security problems)?

I feel like it is more consistent with the current APR interfaces to
have:

  apr_file_t *apr_temp_file(apr_pool_t *pool)
  char *apr_temp_dir(apr_pool_t *pool)

(where the latter creates a new temporary directory) than to have an
apr_get_temp_dir() which the caller uses to construct temporary files
and directories.

I would also say that providing apr_temp_dir() could wait until there is
an identified demand for it.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: apr_file_temp_dir()

Posted by Philip Martin <ph...@codematters.co.uk>.
Greg Hudson <gh...@MIT.EDU> writes:

> On Wed, 2002-11-13 at 11:26, cmpilato@collab.net wrote:
> > This has been mentioned before -- at least by myself, perhaps by
> > others, too -- but the Subversion folks would *really* like to see APR
> > grow a gimme-a-temp-directory function.
> 
> Would gimme-a-temp-file be a better interface?  Like mkstemp(), but
> without the template argument?  (And maybe returning an apr_file_t *
> instead of a file descriptor.)

Suppose I want to create a temporary directory (quite a common
technique to avoid certain security problems)?

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: apr_file_temp_dir()

Posted by Greg Hudson <gh...@MIT.EDU>.
On Wed, 2002-11-13 at 11:26, cmpilato@collab.net wrote:
> This has been mentioned before -- at least by myself, perhaps by
> others, too -- but the Subversion folks would *really* like to see APR
> grow a gimme-a-temp-directory function.

Would gimme-a-temp-file be a better interface?  Like mkstemp(), but
without the template argument?  (And maybe returning an apr_file_t *
instead of a file descriptor.)


Re: apr_file_temp_dir()

Posted by Greg Hudson <gh...@MIT.EDU>.
On Wed, 2002-11-13 at 11:26, cmpilato@collab.net wrote:
> This has been mentioned before -- at least by myself, perhaps by
> others, too -- but the Subversion folks would *really* like to see APR
> grow a gimme-a-temp-directory function.

Would gimme-a-temp-file be a better interface?  Like mkstemp(), but
without the template argument?  (And maybe returning an apr_file_t *
instead of a file descriptor.)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org