fs: Avoid unnecessary lstat() for -literal

Currently, GetLastComponent() always stats (lstat) the file received as
an argument. However, the status information about this file is only
used when 'literal' is false. That said, skip lstat() when 'literal' is
true.

While here, zero out 'statbuff' at the beginning of GetLastComponent()
just to make sure it won't be used uninitialized in the future.

Change-Id: I3f332c53ae688d6f74276bcdbf2f9f61605ec9ad
Reviewed-on: https://gerrit.openafs.org/14840
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
This commit is contained in:
Marcio Barbosa 2023-01-24 14:39:20 +00:00 committed by Andrew Deason
parent 5b01ee836d
commit a0852d93e5

View File

@ -1743,6 +1743,7 @@ GetLastComponent(const char *data, char **outdir, char **outbase,
*outbase = NULL; *outbase = NULL;
*outdir = NULL; *outdir = NULL;
memset(&statbuff, 0, sizeof(statbuff));
if (thru_symlink) if (thru_symlink)
*thru_symlink = 0; *thru_symlink = 0;
@ -1750,7 +1751,7 @@ GetLastComponent(const char *data, char **outdir, char **outbase,
snprintf(orig_name, sizeof(orig_name), "%s%s", snprintf(orig_name, sizeof(orig_name), "%s%s",
(data[0] == '/') ? "" : "./", data); (data[0] == '/') ? "" : "./", data);
if (lstat(orig_name, &statbuff) < 0) { if (!literal && lstat(orig_name, &statbuff) < 0) {
/* if lstat fails, we should still try the pioctl, since it /* if lstat fails, we should still try the pioctl, since it
* may work (for example, lstat will fail, but pioctl will * may work (for example, lstat will fail, but pioctl will
* work if the volume of offline (returning ENODEV). */ * work if the volume of offline (returning ENODEV). */