Skip to content

Commit da5a40c

Browse files
committed
hds-v5: Fix bug erasing top-level HDS objects
1 parent dd461a2 commit da5a40c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

dat1IsTopLevel.c

+26-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@
4444
* If the container file name has more than DAT__SZNAM (15) characters,
4545
* the name stored in the handle associated with the top level object
4646
* will be truncated and so will not equal the name of the container
47-
* file. So only use the first DAT__SZNAM characters when comparing
47+
* file. So only use the first DAT__SZNAM characters when comparing
4848
* the handle name with the container file name.
49+
* 7-MAY-2020 (DSB):
50+
* The name associated with the top-level handle may include a directory
51+
* path. This needs to be removed before comparing it with the name from
52+
* the supplied handle, which will never include a path.
4953
* {enter_further_changes_here}
5054
5155
* Copyright:
@@ -89,16 +93,25 @@
8993
*-
9094
*/
9195
#include <strings.h>
96+
#include <string.h>
9297
#include <pthread.h>
9398

9499
#include "ems.h"
95100
#include "sae_par.h"
96101
#include "dat1.h"
97102
#include "dat_err.h"
98103

104+
#if __MINGW32__
105+
/* Use Windows separator */
106+
#define DIRSEP '\\'
107+
#else
108+
#define DIRSEP '/'
109+
#endif
110+
99111
int dat1IsTopLevel( const HDSLoc *loc, int *status ){
100112

101113
/* Local Variables; */
114+
const char *pname;
102115
int result;
103116
Handle *parent;
104117

@@ -118,7 +131,18 @@ int dat1IsTopLevel( const HDSLoc *loc, int *status ){
118131
truncation of the object name to DAT__SZNAM characters), it is a
119132
top level locator. */
120133
} else if( !parent->parent && loc->handle->name && parent->name ) {
121-
result = !strncasecmp( loc->handle->name, parent->name, DAT__SZNAM );
134+
135+
/* If the parent name contains a directory path, get a pointer to the
136+
first character in the file name. */
137+
pname = strrchr( parent->name, DIRSEP );
138+
if( pname ) {
139+
pname++;
140+
} else {
141+
pname = parent->name;
142+
}
143+
144+
/* Do the comparison, case-insensitive. */
145+
result = !strncasecmp( loc->handle->name, pname, DAT__SZNAM );
122146
}
123147

124148
/* Return the result. */

0 commit comments

Comments
 (0)