Skip to content

Commit

Permalink
micron-nvme: Unuse stat() to check if strMainDirName exists
Browse files Browse the repository at this point in the history
It is checked by mkdir errno EEXIST instead.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Mar 10, 2024
1 parent 1b26176 commit 5b624fa
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions plugins/micron/micron-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ static int SetupDebugDataDirectories(char *strSN, char *strFilePath,
int length = 0;
int nIndex = 0;
char *strTemp = NULL;
struct stat dirStat;
int j;
int k = 0;
int i = 0;
Expand Down Expand Up @@ -304,18 +303,17 @@ static int SetupDebugDataDirectories(char *strSN, char *strFilePath,
strMainDirName[nIndex] = '\0';

j = 1;
while (!stat(strMainDirName, &dirStat)) {
while (mkdir(strMainDirName, 0777) < 0) {
if (errno != EEXIST) {
err = -1;
goto exit_status;
}
strMainDirName[nIndex] = '\0';
sprintf(strAppend, "-%d", j);
strcat(strMainDirName, strAppend);
j++;
}

if (mkdir(strMainDirName, 0777) < 0) {
err = -1;
goto exit_status;
}

if (strOSDirName) {
sprintf(strOSDirName, "%s/%s", strMainDirName, "OS");
if (mkdir(strOSDirName, 0777) < 0) {
Expand All @@ -331,7 +329,7 @@ static int SetupDebugDataDirectories(char *strSN, char *strFilePath,
rmdir(strOSDirName);
rmdir(strMainDirName);
err = -1;
}
}
}

exit_status:
Expand Down

0 comments on commit 5b624fa

Please sign in to comment.