Skip to content

Commit

Permalink
[#230] $ZSEARCH(expr,-1) always returns the first file name matched b…
Browse files Browse the repository at this point in the history
…y search pattern (i.e. no stream)
  • Loading branch information
nars1 committed Oct 29, 2018
1 parent 20c345d commit f686c5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
8 changes: 6 additions & 2 deletions sr_port/op_fnzsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2014, 2015 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
Expand All @@ -17,8 +20,9 @@

#define MAX_STRM_CT 256

#define STRM_ZRUPDATE -1 /* Stream used by ZRUPDATE command when processing wildcards */
#define STRM_COMP_SRC -2 /* Stream used by compile_source_file() */
#define STRM_ALWAYSNEW -1 /* Stream used by $ZSEARCH(expr,-1) to get context that is always new (i.e. no previous stream) */
#define STRM_ZRUPDATE -2 /* Stream used by ZRUPDATE command when processing wildcards */
#define STRM_COMP_SRC -3 /* Stream used by compile_source_file() */

#ifdef UNIX
void zsrch_clr(int indx);
Expand Down
39 changes: 23 additions & 16 deletions sr_unix/op_fnzsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,22 @@ int op_fnzsearch(mval *pattern, mint indx, mint mfunc, mval *ret)
glob_t globbuf;
boolean_t absolute;
intrpt_state_t prev_intrpt_state;
#ifdef _AIX
# ifdef _AIX
boolean_t use_stat;
struct stat statbuf;
#endif
# endif
DCL_THREADGBL_ACCESS;

SETUP_THREADGBL_ACCESS;
if (mfunc && ((MAX_STRM_CT <= indx) || (0 > indx))) /* Allow an out-of-range stream only if used internally. */
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_ZSRCHSTRMCT);
if (mfunc)
{
if (STRM_ALWAYSNEW != indx)
{
if ((MAX_STRM_CT <= indx) || (0 > indx)) /* Allow an out-of-range stream only if used internally. */
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_ZSRCHSTRMCT);
} else
zsrch_clr(STRM_ALWAYSNEW); /* $ZSEARCH(expr,-1) : Special case to start a new stream */
}
ESTABLISH_RET(fnzsrch_ch, -1);
TREF(fnzsearch_nullsubs_sav) = TREF(lv_null_subs);
TREF(lv_null_subs) = LVNULLSUBS_OK; /* $ZSearch processing depends on this. */
Expand Down Expand Up @@ -152,7 +159,7 @@ int op_fnzsearch(mval *pattern, mint indx, mint mfunc, mval *ret)
CANONICALIZE_PATH(buf_ptr);
/* Do not sort the matches because we use $order() to obtain them from a local anyway. */
DEFER_INTERRUPTS(INTRPT_IN_FUNC_WITH_MALLOC, prev_intrpt_state);
#ifdef _AIX
# ifdef _AIX
use_stat = !((pblk.fnb & (1 << V_WILD_NAME)) || (pblk.fnb & (1 << V_WILD_DIR)));
if (use_stat)
{
Expand All @@ -161,7 +168,7 @@ int op_fnzsearch(mval *pattern, mint indx, mint mfunc, mval *ret)
globbuf.gl_pathc = 1;
}
else
#endif
# endif
status = glob(sanitized_buf, LINUX_ONLY(GLOB_PERIOD | ) GLOB_NOSORT,
(int (*)(const char *, int))NULL, &globbuf);
ENABLE_INTERRUPTS(INTRPT_IN_FUNC_WITH_MALLOC, prev_intrpt_state);
Expand All @@ -171,11 +178,11 @@ int op_fnzsearch(mval *pattern, mint indx, mint mfunc, mval *ret)
file.mvtype = MV_STR;
for (i = 0; i < globbuf.gl_pathc; i++)
{ /* We do not care for . and .. */
#ifdef _AIX
# ifdef _AIX
if (use_stat)
match = sanitized_buf;
else
#endif
# endif
match = globbuf.gl_pathv[i];
length = STRLEN(match);
if ((length > 1) && ('.' == match[length - 1]) && (('/' == match[length - 2])
Expand All @@ -195,23 +202,23 @@ int op_fnzsearch(mval *pattern, mint indx, mint mfunc, mval *ret)
match_len = (plength *)&(var_ref->v.m[1]);
SET_LENGTHS(match_len, file.str.addr, length, TRUE);
}
#ifdef _AIX
# ifdef _AIX
if (!use_stat)
{
#endif
# endif
DEFER_INTERRUPTS(INTRPT_IN_FUNC_WITH_MALLOC, prev_intrpt_state);
globfree(&globbuf);
ENABLE_INTERRUPTS(INTRPT_IN_FUNC_WITH_MALLOC, prev_intrpt_state);
TREF(fnzsearch_globbuf_ptr) = NULL;
#ifdef _AIX
# ifdef _AIX
}
#endif
# endif
} else
{
#ifdef _AIX
# ifdef _AIX
if (!use_stat)
{
#endif
# endif
DEFER_INTERRUPTS(INTRPT_IN_FUNC_WITH_MALLOC, prev_intrpt_state);
globfree(&globbuf);
ENABLE_INTERRUPTS(INTRPT_IN_FUNC_WITH_MALLOC, prev_intrpt_state);
Expand All @@ -222,9 +229,9 @@ int op_fnzsearch(mval *pattern, mint indx, mint mfunc, mval *ret)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) EACCES); /* Access error. */
else
assert(GLOB_NOMATCH == status); /* No matches found. */
#ifdef _AIX
# ifdef _AIX
}
#endif
# endif
}
}
}
Expand Down

0 comments on commit f686c5a

Please sign in to comment.