summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2020-07-25 04:47:06 (GMT)
committer Hanhui <hanhui@acoinfo.com>2020-07-25 04:47:06 (GMT)
commite8e6fece0d82f05c0dffaa5e0b2055049805c504 (patch)
tree5ed966b6fae16572a35d89a2b36fb861510bca75 /SylixOS
parent8e58c89af9a0c3b0656fe53064330911c56fe489 (diff)
downloadlibsylixos-e8e6fece0d82f05c0dffaa5e0b2055049805c504.zip
libsylixos-e8e6fece0d82f05c0dffaa5e0b2055049805c504.tar.gz
libsylixos-e8e6fece0d82f05c0dffaa5e0b2055049805c504.tar.bz2
Fixed 'cp' command same file bug.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/shell/fsLib/ttinyShellFsCmd.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/SylixOS/shell/fsLib/ttinyShellFsCmd.c b/SylixOS/shell/fsLib/ttinyShellFsCmd.c
index 5b925fb..85f83ac 100644
--- a/SylixOS/shell/fsLib/ttinyShellFsCmd.c
+++ b/SylixOS/shell/fsLib/ttinyShellFsCmd.c
@@ -942,6 +942,16 @@ static INT __tshellFsCmdCp (INT iArgC, PCHAR ppcArgV[])
lib_strlcpy(cDstFile, pcDest, MAX_FILENAME_LENGTH);
}
+ iError = stat(cDstFile, &statDst); /* 获得目标文件属性 */
+ if (iError == ERROR_NONE) { /* 目标文件存在 */
+ if ((statDst.st_dev == statFile.st_dev) &&
+ (statDst.st_ino == statFile.st_ino)) { /* 源文件与目标文件相同 */
+ close(iFdSrc);
+ fprintf(stderr, "'%s' and '%s' are the same file!\n", pcSrc, cDstFile);
+ return (PX_ERROR);
+ }
+ }
+
if (!bForce) {
iError = access(cDstFile, 0); /* 检测目标文件是否存在 */
if (iError == ERROR_NONE) {