Skip to content

Commit

Permalink
Revert r1862435, r1862071 per veto from ivan
Browse files Browse the repository at this point in the history
msgid: <CABw-3YcK0qbeYWDOwE684XtBj3rCT2CuVOBWWqda4gMtRyRJEw@mail.gmail.com>


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1866019 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Aug 28, 2019
1 parent c715603 commit 5514d03
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 127 deletions.
7 changes: 0 additions & 7 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ Changes for APR 2.0.0

*) apr_thread_exit() is now a void function. [Joe Orton]

*) apr_dir_read(): The returned finfo->name field is now duplicated
into the pool for all implementations. [Joe Orton]

*) apr_dir_pread(): Add function which restricts per-read memory
consumption to a different pool to the apr_dir_t object.
[Joe Orton]

*) apr_crypto_openssl: Remove unused link to the ssl library.
[Graham Leggett]

Expand Down
14 changes: 5 additions & 9 deletions file_io/os2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,24 @@ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir)
return APR_FROM_OS_ERROR(rv);
}



APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir)
{
return apr_dir_pread(finfo, wanted, thedir, thedir->pool);
}

APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir, apr_pool_t *pool)
{
int rv;
ULONG entries = 1;

if (thedir->handle == 0) {
thedir->handle = HDIR_CREATE;
rv = DosFindFirst(apr_pstrcat(pool, thedir->dirname, "/*", NULL), &thedir->handle,
rv = DosFindFirst(apr_pstrcat(thedir->pool, thedir->dirname, "/*", NULL), &thedir->handle,
FILE_ARCHIVED|FILE_DIRECTORY|FILE_SYSTEM|FILE_HIDDEN|FILE_READONLY,
&thedir->entry, sizeof(thedir->entry), &entries, FIL_STANDARD);
} else {
rv = DosFindNext(thedir->handle, &thedir->entry, sizeof(thedir->entry), &entries);
}

finfo->pool = pool;
finfo->pool = thedir->pool;
finfo->fname = NULL;
finfo->valid = 0;

Expand All @@ -122,7 +118,7 @@ APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
apr_os2_time_to_apr_time(&finfo->ctime, thedir->entry.fdateCreation,
thedir->entry.ftimeCreation);

finfo->name = apr_pstrdup(pool, thedir->entry.achName);
finfo->name = thedir->entry.achName;
finfo->valid = APR_FINFO_NAME | APR_FINFO_MTIME | APR_FINFO_ATIME |
APR_FINFO_CTIME | APR_FINFO_TYPE | APR_FINFO_SIZE |
APR_FINFO_CSIZE;
Expand Down
12 changes: 3 additions & 9 deletions file_io/unix/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ static apr_filetype_e filetype_from_dirent_type(int type)

apr_status_t apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir)
{
return apr_dir_pread(finfo, wanted, thedir, thedir->pool);
}

apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir, apr_pool_t *pool)
{
apr_status_t ret = 0;
#ifdef DIRENT_TYPE
Expand Down Expand Up @@ -257,7 +251,7 @@ apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
apr_cpystrn(end, thedir->entry->d_name,
sizeof fspec - (end - fspec));

ret = apr_stat(finfo, fspec, APR_FINFO_LINK | wanted, pool);
ret = apr_stat(finfo, fspec, APR_FINFO_LINK | wanted, thedir->pool);
/* We passed a stack name that will disappear */
finfo->fname = NULL;
}
Expand All @@ -269,7 +263,7 @@ apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
/* We don't bail because we fail to stat, when we are only -required-
* to readdir... but the result will be APR_INCOMPLETE
*/
finfo->pool = pool;
finfo->pool = thedir->pool;
finfo->valid = 0;
#ifdef DIRENT_TYPE
if (type != APR_UNKFILE) {
Expand All @@ -285,7 +279,7 @@ apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
#endif
}

finfo->name = apr_pstrdup(pool, thedir->entry->d_name);
finfo->name = apr_pstrdup(thedir->pool, thedir->entry->d_name);
finfo->valid |= APR_FINFO_NAME;

if (wanted)
Expand Down
10 changes: 2 additions & 8 deletions file_io/win32/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *dir)

APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir)
{
return apr_dir_pread(finfo, wanted, thedir, thedir->pool);
}

APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir, apr_pool_t *pool)
{
apr_status_t rv;
char *fname;
Expand Down Expand Up @@ -152,11 +146,11 @@ APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
if ((rv = unicode_to_utf8_path(thedir->name, APR_FILE_MAX * 3 + 1,
thedir->entry->cFileName)))
return rv;
fname = apr_pstrdup(pool, thedir->name);
fname = thedir->name;

fillin_fileinfo(finfo, (WIN32_FILE_ATTRIBUTE_DATA *) thedir->entry,
0, 1, fname, wanted);
finfo->pool = pool;
finfo->pool = thedir->pool;

finfo->valid |= APR_FINFO_NAME;
finfo->name = fname;
Expand Down
28 changes: 0 additions & 28 deletions include/apr_file_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,44 +257,16 @@ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir);
* @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
values
* @param thedir the directory descriptor returned from apr_dir_open
*
* @remark No ordering is guaranteed for the entries read.
* @c finfo->pool is set to the pool used to create @a thedir,
* and @c finfo->name is allocated from that pool.
*
* @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
* not be filled in, and you need to check the @c finfo->valid bitmask
* to verify that what you're looking for is there. When no more
* entries are available, APR_ENOENT is returned.
*
* @warning Allocations will use the directory pool; use
* apr_dir_pread() and a temporary pool to restrict memory
* consumption for a large directory.
*/
APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir);

/**
* Read the next entry from the specified directory.
* @param finfo the file info structure and filled in by apr_dir_read
* @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
values
* @param thedir the directory descriptor returned from apr_dir_open
* @param pool the pool to use for allocations
* @remark No ordering is guaranteed for the entries read.
* @remark @c finfo->pool is set to @a pool, and @c finfo->name is
* allocated from that pool.
*
* @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
* not be filled in, and you need to check the @c finfo->valid bitmask
* to verify that what you're looking for is there. When no more
* entries are available, APR_ENOENT is returned.
*/
APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir, apr_pool_t *pool);


/**
* Rewind the directory to the first entry.
* @param thedir the directory descriptor to rewind.
Expand Down
67 changes: 1 addition & 66 deletions test/testdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "apr_file_info.h"
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_thread_proc.h"
#include "testutil.h"
Expand Down Expand Up @@ -431,66 +430,6 @@ static void test_readmore_info(abts_case* tc, void* data)
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}

#if APR_POOL_DEBUG
static void test_pread(abts_case *tc, void *data)
{
apr_dir_t *dir;
apr_finfo_t finfo;
apr_size_t before, after;
apr_pool_t *subp;

APR_ASSERT_SUCCESS(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p));

apr_pool_create(&subp, p);

before = apr_pool_num_bytes(p, 0);

APR_ASSERT_SUCCESS(tc, "apr_dir_read failed",
apr_dir_pread(&finfo, APR_FINFO_DIRENT, dir, subp));

after = apr_pool_num_bytes(p, 0);

ABTS_PTR_EQUAL(tc, finfo.pool, subp);

apr_pool_destroy(subp);

APR_ASSERT_SUCCESS(tc, "apr_dir_close failed", apr_dir_close(dir));

ABTS_INT_EQUAL(tc, before, after);

}
#endif

/* Ensure that apr_dir_read() doesn't have side-effects, because
* finfo->name points to a static buffer inside the apr_dir_t */
static void test_read_side_effects(abts_case *tc, void *data)
{
apr_dir_t *dir;
apr_finfo_t f1;
apr_finfo_t f2;
char name[APR_PATH_MAX], fname[APR_PATH_MAX];

APR_ASSERT_SUCCESS(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p));

APR_ASSERT_SUCCESS(tc, "apr_dir_read failed",
apr_dir_read(&f1, APR_FINFO_DIRENT, dir));

if (f1.name)
apr_cpystrn(name, f1.name, sizeof name);
if (f1.fname)
apr_cpystrn(fname, f1.fname, sizeof fname);

APR_ASSERT_SUCCESS(tc, "second apr_dir_read failed",
apr_dir_read(&f2, APR_FINFO_DIRENT, dir));

if (f1.name)
ABTS_STR_EQUAL(tc, name, f1.name);
if (f1.fname)
ABTS_STR_EQUAL(tc, fname, f1.fname);

APR_ASSERT_SUCCESS(tc, "apr_dir_close failed", apr_dir_close(dir));
}

abts_suite *testdir(abts_suite *suite)
{
suite = ADD_SUITE(suite)
Expand All @@ -512,11 +451,7 @@ abts_suite *testdir(abts_suite *suite)
abts_run_test(suite, test_closedir, NULL);
abts_run_test(suite, test_uncleared_errno, NULL);
abts_run_test(suite, test_readmore_info, NULL);
#if APR_POOL_DEBUG
abts_run_test(suite, test_pread, NULL);
#endif
abts_run_test(suite, test_read_side_effects, NULL);


return suite;
}

0 comments on commit 5514d03

Please sign in to comment.