提交 a0bb801f 编写于 作者: O openharmony_ci 提交者: Gitee

!114 Fix OHOS shell cannot ls a file for branch release

Merge pull request !114 from ysy4tc3/fork_release
...@@ -526,16 +526,74 @@ static void PrintFileInfo(const struct stat *statInfo, const char *name) ...@@ -526,16 +526,74 @@ static void PrintFileInfo(const struct stat *statInfo, const char *name)
str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size, statInfo->st_uid, statInfo->st_gid, name); str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size, statInfo->st_uid, statInfo->st_gid, name);
} }
void ls(const char *pathname) int LsFile(const char *path)
{ {
struct stat64 stat64_info; struct stat64 stat64Info;
struct stat stat_info; struct stat statInfo;
struct dirent *pdirent = NULL;
char *path = NULL; if (stat64(path, &stat64Info) == 0) {
PrintFileInfo64(&stat64Info, path);
} else if (stat(path, &statInfo) == 0) {
PrintFileInfo(&statInfo, path);
} else {
return -1;
}
return 0;
}
int LsDir(const char *path)
{
struct stat statInfo = { 0 };
struct stat64 stat64Info = { 0 };
DIR *d = NULL;
char *fullpath = NULL; char *fullpath = NULL;
char *fullpath_bak = NULL; char *fullpath_bak = NULL;
struct dirent *pdirent = NULL;
d = opendir(path);
if (d == NULL) {
return -1;
}
PRINTK("Directory %s:\n", path);
do {
pdirent = readdir(d);
if (pdirent == NULL) {
break;
} else {
if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
continue;
}
(void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
(void)memset_s(&stat64Info, sizeof(struct stat), 0, sizeof(struct stat));
fullpath = ls_get_fullpath(path, pdirent);
if (fullpath == NULL) {
(void)closedir(d);
return -1;
}
fullpath_bak = fullpath;
if (stat64(fullpath, &stat64Info) == 0) {
PrintFileInfo64(&stat64Info, pdirent->d_name);
} else if (stat(fullpath, &statInfo) == 0) {
PrintFileInfo(&statInfo, pdirent->d_name);
} else {
PRINTK("BAD file: %s\n", pdirent->d_name);
}
free(fullpath_bak);
}
} while (1);
(void)closedir(d);
return 0;
}
void ls(const char *pathname)
{
struct stat statInfo = { 0 };
char *path = NULL;
int ret; int ret;
DIR *d = NULL;
if (pathname == NULL) { if (pathname == NULL) {
#ifdef VFS_USING_WORKDIR #ifdef VFS_USING_WORKDIR
...@@ -561,45 +619,23 @@ void ls(const char *pathname) ...@@ -561,45 +619,23 @@ void ls(const char *pathname)
} }
} }
/* list all directory and file*/ ret = stat(path, &statInfo);
if (ret < 0) {
d = opendir(path);
if (d == NULL) {
perror("ls error"); perror("ls error");
} else {
PRINTK("Directory %s:\n", path);
do {
pdirent = readdir(d);
if (pdirent == NULL) {
break;
} else {
if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
continue;
}
(void)memset_s(&stat_info, sizeof(struct stat), 0, sizeof(struct stat));
fullpath = ls_get_fullpath(path, pdirent);
if (fullpath == NULL) {
free(path); free(path);
(void)closedir(d);
return; return;
} }
fullpath_bak = fullpath; if (statInfo.st_mode & S_IFDIR) { /* list all directory and file */
ret = LsDir((pathname == NULL) ? path : pathname);
if (stat64(fullpath, &stat64_info) == 0) { } else { /* show the file infomation */
PrintFileInfo64(&stat64_info, pdirent->d_name); ret = LsFile(path);
} else if (stat(fullpath, &stat_info) == 0) {
PrintFileInfo(&stat_info, pdirent->d_name);
} else
PRINTK("BAD file: %s\n", pdirent->d_name);
free(fullpath_bak);
} }
} while (1); if (ret < 0) {
perror("ls error");
(void)closedir(d);
} }
free(path);
free(path);
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册