Skip to content

Commit f4d2ff0

Browse files
committed
fix pester test failures
1 parent 215341d commit f4d2ff0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

contrib/win32/win32compat/win32_dirent.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,27 @@ readdir(void *avp)
268268
char *
269269
basename(char *path)
270270
{
271-
char *pdest;
271+
char *pdest;
272+
const char *endp;
273+
static char bname[PATH_MAX];
274+
275+
/* Find any trailing slashes */
276+
endp = path + strlen(path) - 1;
277+
while (endp > path && (*endp == '/' || *endp == '\\'))
278+
endp--;
279+
280+
int path_len = endp - path + 1;
281+
if (strncpy_s(bname, PATH_MAX, path, path_len + 1)) {
282+
return NULL;
283+
}
284+
bname[path_len] = '\0';
272285

273286
if (!path)
274287
return ".";
275-
pdest = strrchr(path, '/');
288+
pdest = strrchr(bname, '/');
276289
if (pdest)
277290
return (pdest + 1);
278-
pdest = strrchr(path, '\\');
291+
pdest = strrchr(bname, '\\');
279292
if (pdest)
280293
return (pdest + 1);
281294

sftp-client.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,11 @@ do_download(struct sftp_conn *conn, const char *remote_path,
18191819
status = SSH2_FX_FAILURE;
18201820
else
18211821
status = SSH2_FX_OK;
1822+
#ifdef WINDOWS
1823+
if (add_mark_of_web(local_path) == -1) {
1824+
debug("%s: failed to add mark of the web", local_path);
1825+
}
1826+
#endif // WINDOWS
18221827
/* Override umask and utimes if asked */
18231828
#ifdef HAVE_FCHMOD
18241829
if (preserve_flag && fchmod(local_fd, mode) == -1)
@@ -1847,11 +1852,6 @@ do_download(struct sftp_conn *conn, const char *remote_path,
18471852
}
18481853
}
18491854
close(local_fd);
1850-
#ifdef WINDOWS
1851-
if (add_mark_of_web(local_path) == -1) {
1852-
debug("%s: failed to add mark of the web", local_path);
1853-
}
1854-
#endif // WINDOWS
18551855
sshbuf_free(msg);
18561856
free(handle);
18571857

0 commit comments

Comments
 (0)