From da1c1e732365fb107f956a68b02c388ff10e1e7a Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Wed, 23 Jan 2002 18:28:05 +0000 Subject: [PATCH] Eliminate a large number of Win32-isms. In large part, these can apply to other one-off platforms such as OS2, and immediately impact a new port which played by all the APR rules. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92983 13f79535-47bb-0310-9956-ffa450edef68 --- modules/dav/fs/lock.c | 28 ++++++----- modules/dav/fs/repos.c | 103 +++++++++++++++++++++++++---------------- 2 files changed, 81 insertions(+), 50 deletions(-) diff --git a/modules/dav/fs/lock.c b/modules/dav/fs/lock.c index 1e9ff78c80..f063fc5e12 100644 --- a/modules/dav/fs/lock.c +++ b/modules/dav/fs/lock.c @@ -435,23 +435,28 @@ static apr_datum_t dav_fs_build_fname_key(apr_pool_t *p, const char *pathname) ** dav_fs_build_key: Given a resource, return a apr_datum_t key ** to look up lock information for this file. ** -** (Win32 or file is lock-null): +** (inode/dev not supported or file is lock-null): ** apr_datum_t->dvalue = full path ** -** (non-Win32 and file exists ): -** apr_datum_t->dvalue = inode, dev_major, dev_minor +** (inode/dev supported and file exists ): +** apr_datum_t->dvalue = inode, dev */ static apr_datum_t dav_fs_build_key(apr_pool_t *p, const dav_resource *resource) { const char *file = dav_fs_pathname(resource); -#ifndef WIN32 apr_datum_t key; apr_finfo_t finfo; + apr_status_t rv; /* ### use lstat() ?? */ - if (apr_stat(&finfo, file, APR_FINFO_NORM, p) == APR_SUCCESS) { - + /* + * XXX: What for platforms with no IDENT (dev/inode)? + */ + rv = apr_stat(&finfo, file, APR_FINFO_IDENT, p); + if ((rv == APR_SUCCESS || rv == APR_INCOMPLETE) + && ((finfo.valid & APR_FINFO_IDENT) == APR_FINFO_IDENT)) + { /* ### can we use a buffer for this? */ key.dsize = 1 + sizeof(finfo.inode) + sizeof(finfo.device); key.dptr = apr_palloc(p, key.dsize); @@ -462,7 +467,6 @@ static apr_datum_t dav_fs_build_key(apr_pool_t *p, return key; } -#endif return dav_fs_build_fname_key(p, file); } @@ -664,9 +668,11 @@ static dav_error * dav_fs_load_lock_record(dav_lockdb *lockdb, apr_datum_t key, if (*key.dptr == DAV_TYPE_FNAME) { const char *fname = key.dptr + 1; apr_finfo_t finfo; + apr_status_t rv; /* if we don't see the file, then it's a locknull */ - if (apr_lstat(&finfo, fname, APR_FINFO_NORM, p) != APR_SUCCESS) { + rv = apr_lstat(&finfo, fname, APR_FINFO_MIN, p); + if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) { if ((err = dav_fs_remove_locknull_member(p, fname, &buf)) != NULL) { /* ### push a higher-level description? */ return err; @@ -821,6 +827,7 @@ static dav_error * dav_fs_load_locknull_list(apr_pool_t *p, const char *dirpath, apr_file_t *file = NULL; dav_error *err = NULL; apr_size_t amt; + apr_status_t rv; dav_buffer_init(p, pbuf, dirpath); @@ -837,7 +844,8 @@ static dav_error * dav_fs_load_locknull_list(apr_pool_t *p, const char *dirpath, return NULL; } - if (apr_file_info_get(&finfo, APR_FINFO_NORM, file) != APR_SUCCESS) { + rv = apr_file_info_get(&finfo, APR_FINFO_NORM, file); + if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) { err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, apr_psprintf(p, "Opened but could not stat file %s", @@ -1042,7 +1050,6 @@ static dav_error * dav_fs_remove_locknull_state( return err; } -#ifndef WIN32 { dav_lock_discovery *ld; dav_lock_indirect *id; @@ -1071,7 +1078,6 @@ static dav_error * dav_fs_remove_locknull_state( return err; } } -#endif return NULL; } diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 8ea05944c6..a74adf9e52 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -244,17 +244,43 @@ void dav_fs_dir_file_name( *fname_p = NULL; } else { + const char *testpath, *rootpath; char *dirpath = ap_make_dirstr_parent(ctx->pool, ctx->pathname); apr_size_t dirlen = strlen(dirpath); + apr_status_t rv = APR_SUCCESS; - if (fname_p != NULL) - *fname_p = ctx->pathname + dirlen; - *dirpath_p = dirpath; - - /* remove trailing slash from dirpath, unless it's the root dir */ - /* ### Win32 check */ - if (dirlen > 1 && dirpath[dirlen - 1] == '/') { - dirpath[dirlen - 1] = '\0'; + testpath = dirpath; + if (dirlen > 0) { + rv = apr_filepath_root(&rootpath, &testpath, 0, ctx->pool); + } + + /* remove trailing slash from dirpath, unless it's a root path + */ + if ((rv == APR_SUCCESS && testpath && *testpath) + || rv == APR_ERELATIVE) { + if (dirpath[dirlen - 1] == '/') { + dirpath[dirlen - 1] = '\0'; + } + } + + /* ###: Looks like a response could be appropriate + * + * APR_SUCCESS here tells us the dir is a root + * APR_ERELATIVE told us we had no root (ok) + * APR_EINCOMPLETE an incomplete testpath told us + * there was no -file- name here! + * APR_EBADPATH or other errors tell us this file + * path is undecipherable + */ + + if (rv == APR_SUCCESS || rv == APR_ERELATIVE) { + *dirpath_p = dirpath; + if (fname_p != NULL) + *fname_p = ctx->pathname + dirlen; + } + else { + if (fname_p != NULL) + *fname_p = NULL; } } } @@ -426,7 +452,8 @@ static dav_error * dav_fs_copymove_state( src = apr_pstrcat(p, src_dir, "/" DAV_FS_STATE_DIR "/", src_file, NULL); /* the source file doesn't exist */ - if (apr_stat(&src_finfo, src, APR_FINFO_NORM, p) != APR_SUCCESS) { + rv = apr_stat(&src_finfo, src, APR_FINFO_NORM, p); + if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) { return NULL; } @@ -446,7 +473,8 @@ static dav_error * dav_fs_copymove_state( } /* get info about the state directory */ - if (apr_stat(&dst_state_finfo, dst, APR_FINFO_NORM, p) != APR_SUCCESS) { + rv = apr_stat(&dst_state_finfo, dst, APR_FINFO_NORM, p); + if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) { /* Ack! Where'd it go? */ /* ### use something besides 500? */ return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, @@ -705,16 +733,12 @@ static dav_error * dav_fs_get_parent_resource(const dav_resource *resource, dav_resource_private *ctx = resource->info; dav_resource_private *parent_ctx; dav_resource *parent_resource; + apr_status_t rv; char *dirpath; /* If given resource is root, then there is no parent */ if (strcmp(resource->uri, "/") == 0 || -#ifdef WIN32 - (strlen(ctx->pathname) == 3 && ctx->pathname[1] == ':' && ctx->pathname[2] == '/') -#else - strcmp(ctx->pathname, "/") == 0 -#endif - ) { + ap_os_is_path_absolute(ctx->pool, ctx->pathname)) { *result_parent = NULL; return NULL; } @@ -745,8 +769,9 @@ static dav_error * dav_fs_get_parent_resource(const dav_resource *resource, parent_resource->uri = uri; } - if (apr_stat(&parent_ctx->finfo, parent_ctx->pathname, - APR_FINFO_NORM, ctx->pool) == APR_SUCCESS) { + apr_stat(&parent_ctx->finfo, parent_ctx->pathname, + APR_FINFO_NORM, ctx->pool); + if (rv == APR_SUCCESS || rv == APR_INCOMPLETE) { parent_resource->exists = 1; } @@ -764,14 +789,13 @@ static int dav_fs_is_same_resource( if (res1->hooks != res2->hooks) return 0; -#ifdef WIN32 - return stricmp(ctx1->pathname, ctx2->pathname) == 0; -#else - if (ctx1->finfo.filetype != 0) + if ((ctx1->finfo.filetype != 0) && (ctx2->finfo.filetype != 0) + && (ctx1->finfo.valid & ctx2->finfo.valid & APR_FINFO_INODE)) { return ctx1->finfo.inode == ctx2->finfo.inode; - else + } + else { return strcmp(ctx1->pathname, ctx2->pathname) == 0; -#endif + } } static int dav_fs_is_parent_resource( @@ -1171,13 +1195,21 @@ static dav_error * dav_fs_move_resource( else { const char *dirpath; apr_finfo_t finfo; + apr_status_t rv; /* destination does not exist, but the parent directory should, * so try it */ dirpath = ap_make_dirstr_parent(dstinfo->pool, dstinfo->pathname); - if (apr_stat(&finfo, dirpath, APR_FINFO_NORM, dstinfo->pool) == 0 - && finfo.device == srcinfo->finfo.device) { + /* + * XXX: If missing dev ... then what test? + * Really need a try and failover for those platforms. + * + */ + rv = apr_stat(&finfo, dirpath, APR_FINFO_DEV, dstinfo->pool); + if ((rv == APR_SUCCESS || rv == APR_INCOMPLETE) + && (finfo.valid & srcinfo->finfo.valid & APR_FINFO_DEV) + && (finfo.device == srcinfo->finfo.device)) { can_rename = 1; } } @@ -1868,11 +1900,11 @@ static int dav_fs_is_writable(const dav_resource *resource, int propid) { const dav_liveprop_spec *info; -#ifndef WIN32 - /* this property is not usable (writable) on the Win32 platform */ + /* XXX this property is not usable (writable) on all platforms + * Need an abstract way to determine this. + */ if (propid == DAV_PROPID_FS_executable && !resource->collection) return 1; -#endif (void) dav_get_liveprop_info(propid, &dav_fs_liveprop_group, &info); return info->is_writable; @@ -2036,10 +2068,11 @@ static const dav_provider dav_fs_provider = void dav_fs_gather_propsets(apr_array_header_t *uris) { -#ifndef WIN32 + /* XXX: Need an abstract way to determine this on a per-filesystem basis + * This may change by uri (!) (think OSX HFS + unix mounts). + */ *(const char **)apr_array_push(uris) = ""; -#endif } int dav_fs_find_liveprop(const dav_resource *resource, @@ -2077,16 +2110,8 @@ void dav_fs_insert_all_liveprops(request_rec *r, const dav_resource *resource, what, phdr); (void) dav_fs_insert_prop(resource, DAV_PROPID_getetag, what, phdr); - -#ifndef WIN32 - /* - ** Note: this property is not defined on the Win32 platform. - ** dav_fs_insert_prop() won't insert it, but we may as - ** well not even call it. - */ (void) dav_fs_insert_prop(resource, DAV_PROPID_FS_executable, what, phdr); -#endif /* ### we know the others aren't defined as liveprops */ } -- 2.40.0