forked from adrianlopezroche/fdupes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call stat() before deleting any file to ensure it's still the same file.
- Loading branch information
1 parent
4b6bcde
commit 8568089
Showing
5 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "removeifnotchanged.h" | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
int removeifnotchanged(const file_t *file, char **errorstring) | ||
{ | ||
int result; | ||
struct stat st; | ||
|
||
static char *filechanged = "File contents changed during processing"; | ||
static char *unknownerror = "Unknown error"; | ||
|
||
stat(file->d_name, &st); | ||
|
||
if (file->device != st.st_dev || | ||
file->inode != st.st_ino || | ||
file->ctime != st.st_ctime || | ||
file->mtime != st.st_mtime || | ||
file->size != st.st_size) | ||
{ | ||
if (errorstring != 0) | ||
*errorstring = filechanged; | ||
|
||
return -2; | ||
} | ||
else | ||
{ | ||
result = remove(file->d_name); | ||
|
||
if (result != 0 && errorstring != 0) | ||
{ | ||
*errorstring = strerror(errno); | ||
|
||
if (*errorstring == 0) | ||
*errorstring = unknownerror; | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef REMOVEIFNOTCHANGED_H | ||
#define REMOVEIFNOTCHANGED_H | ||
|
||
#include "fdupes.h" | ||
|
||
int removeifnotchanged(const file_t *file, char **errorstring); | ||
|
||
#endif |