Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a1fc93b

Browse files
committed
2 parents ef77861 + ef3edaf commit a1fc93b

File tree

4 files changed

+18
-71
lines changed

4 files changed

+18
-71
lines changed

‎monitoring.c‎

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ void monitoring(void) // 모니터링
1010
FILE *fp; // log.txt 파일 구조체
1111
int old_list_cnt, new_list_cnt; // 모니터링 디렉토리 파일 개수(기존, 신규)
1212
file_node *old_list, *new_list; // 모니터링 디렉토리 트리(기존, 신규)
13-
int is_first;
1413
int change_list_cnt;
15-
time_t start_t;
1614

1715
getcwd(pwd, BUFFER_SIZE);
1816
sprintf(check_path, "%s/%s", pwd, CHECK);
@@ -32,23 +30,13 @@ void monitoring(void) // 모니터링
3230
// 프로세스 이름 변경
3331
prctl(PR_SET_NAME, "ssu_mntr-daemon0円", NULL, NULL, NULL);
3432

35-
start_t = time(NULL);
36-
is_first = true;
33+
old_list = make_list(check_path);
3734

3835
while(true) {
3936

4037
change_list_cnt = 0;
4138

4239
new_list = make_list(check_path); // 현재 파일 목록 및 상태 저장
43-
new_list_cnt = count_file(new_list->child); // 현재 목록에 존재하는 파일 개수
44-
init_list_status(new_list->child, UNCHCK); // 현재 파일 목록 모니터링 상태 초기화
45-
46-
if(is_first) { // 최초 실행일 경우
47-
old_list = new_list;
48-
old_list_cnt = new_list_cnt;
49-
is_first = false;
50-
continue;
51-
}
5240

5341
compare_list(new_list->child, old_list->child); // 파일 목록 트리 비교
5442
change_list_cnt = write_change_list(new_list->child, change_list_cnt, CREATE); // 생성된 파일 확인
@@ -59,12 +47,10 @@ void monitoring(void) // 모니터링
5947
free_list(old_list);
6048

6149
old_list = new_list;
62-
old_list_cnt = new_list_cnt;
6350
init_list_status(old_list->child, UNCHCK);
6451

6552
sleep(1);
6653
}
67-
exit(0);
6854
}
6955

7056

@@ -74,10 +60,7 @@ void init_list_status(file_node *head, int status) // 모니터링 파일 상태
7460

7561
now = head;
7662

77-
while(true) {
78-
79-
if(now == NULL)
80-
break;
63+
while(now != NULL) {
8164

8265
now->status = status;
8366

@@ -88,30 +71,6 @@ void init_list_status(file_node *head, int status) // 모니터링 파일 상태
8871
}
8972
}
9073

91-
int count_file(file_node *head) // 파일 개수 반환
92-
{
93-
int cnt;
94-
file_node *now;
95-
96-
now = head;
97-
cnt = false;
98-
99-
while(true) { // 개수 탐색 시작
100-
101-
if(now == NULL)
102-
break;
103-
104-
cnt++;
105-
106-
if(now->child != NULL) // 현재 탐색하는 파일이 디렉토리일 경우
107-
cnt += count_file(now->child); // 해당 디렉토리 파일 개수 재귀 탐색
108-
109-
now = now->next; // 다음 파일 탐색
110-
}
111-
112-
return cnt;
113-
}
114-
11574
void compare_list(file_node *new_list, file_node *old_list) // 파일 목록 트리 비교
11675
{
11776
file_node *now;
@@ -121,10 +80,7 @@ void compare_list(file_node *new_list, file_node *old_list) // 파일 목록 트
12180

12281
now = old_list;
12382

124-
while(true) {
125-
126-
if(now == NULL)
127-
break;
83+
while(now != NULL) {
12884

12985
compare_file(new_list, now);
13086

@@ -141,10 +97,7 @@ int compare_file(file_node *new_file, file_node *old_file) // 파일 정보 비
14197

14298
now = new_file;
14399

144-
while(true) {
145-
146-
if(now == NULL)
147-
break;
100+
while(now != NULL) {
148101

149102
if(!strcmp(now->name, old_file->name)) { // 해당 이름을 가진 파일이 기존에 이미 존재할 경우
150103
now->status = CHCKED;
@@ -172,10 +125,7 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
172125

173126
now = head;
174127

175-
while(true) {
176-
177-
if(now == NULL)
178-
break;
128+
while(now != NULL) {
179129

180130
switch(now->status) {
181131
case UNCHCK:

‎monitoring.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ typedef struct ssu_changeItem { // 변경사항 구조체
88

99
void monitoring(void); // 모니터링
1010
void init_list_status(file_node *head, int status); // 모니터링 파일 상태 초기화
11-
int count_file(file_node *head); // 파일 개수 반환
1211
void compare_list(file_node *new_list, file_node *old_list); // 파일 목록 트리 비교
1312
int compare_file(file_node *new_file, file_node *old_file); // 파일 정보 비교
1413
int write_change_list(file_node *head, int idx, int status); // 변경 사항 목록 작성

‎prompt.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ commands make_command_token(char *command_line) // 명령어 전체 문장 토
327327
}
328328

329329
to_lower_case(command); // 명령어 소문자화
330-
result.argv[result.argc] = (char *)calloc(strlen(command), sizeof(char)); // 메모리 공간 할당
330+
result.argv[result.argc] = (char *)calloc(BUFFER_SIZE, sizeof(char)); // 메모리 공간 할당
331331
strcpy(result.argv[result.argc++], command); // 토큰 배열에 복사
332332

333333
while((tmp = strtok(NULL, " ")) != NULL) { // 나머지 인자 복사
334-
result.argv[result.argc] = (char *)calloc(strlen(command), sizeof(char)); // 메모리 공간 할당
334+
result.argv[result.argc] = (char *)calloc(BUFFER_SIZE, sizeof(char)); // 메모리 공간 할당
335335
strcpy(result.argv[result.argc++], tmp); // 토큰 배열에 복사
336336
}
337337

@@ -355,7 +355,7 @@ int get_command_type(char *command) // COMMAND 타입 확인 및 반환
355355
return EXIT;
356356
else if(!strcmp(command, "help"))
357357
return HELP;
358-
else
358+
else
359359
return UNKNOWN;
360360
}
361361

@@ -753,7 +753,7 @@ int find_trash_overlap(const char *file_name) // 휴지통 중복 파일 탐색
753753

754754
if(overlap_count > 0) {
755755
chdir(pwd);
756-
return overlap_count+1;
756+
return overlap_count;
757757
}
758758

759759
chdir(pwd);
@@ -767,10 +767,7 @@ void print_list_size(file_node *head, char *path, int number, int option_d, int
767767

768768
now = head;
769769

770-
while(number > 0) {
771-
772-
if(now == NULL) // 파일이 존재하지 않을 경우
773-
break;
770+
while(number > 0 && now != NULL) {
774771

775772
relative_path = now->name + strlen(pwd); // 상대 경로 추출
776773
printf("%-10d.%-s\n", now->size, relative_path); // 출력
@@ -1139,7 +1136,7 @@ void print_list_tree(file_node *head, int level, int level_check[], int is_root)
11391136

11401137
now = head;
11411138

1142-
while(true) {
1139+
while(now!=NULL) {
11431140
file_name = get_file_name(now->name);
11441141

11451142
if(is_root) { // 루트 디렉토리 노드일 경우 디렉토리 이름만 출력 후 하위 파일 노드로 이동
@@ -1175,10 +1172,8 @@ void print_list_tree(file_node *head, int level, int level_check[], int is_root)
11751172
print_list_tree(now->child, level + 1, level_check, is_root);
11761173
}
11771174

1178-
if(now->next != NULL)
1179-
now = now->next;
1175+
now = now->next;
11801176

1181-
else break;
11821177
}
11831178
}
11841179

‎support.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ file_node *make_list(char *path) // 디렉토리 파일 목록 트리화
1919
file_node *head, *now;
2020
// 파일 : 노드 생성(절대경로/이름, 상태정보)
2121
// 디렉토리: 트리 생성
22-
DIR *dp;
2322
int file_count;
2423
int is_dirattr = true;
2524
int i;
@@ -57,7 +56,7 @@ file_node *make_list(char *path) // 디렉토리 파일 목록 트리화
5756
now = now->next;
5857
}
5958
}
60-
head->size = count_size(head->child);
59+
head->size = count_size(head);
6160
return head;
6261
}
6362

@@ -67,7 +66,11 @@ int count_size(file_node *head) // 디렉토리 크기 반환
6766
int size;
6867

6968
size = false;
70-
now = head;
69+
70+
if(S_ISDIR(head->attr.st_mode))
71+
now = head->child;
72+
else
73+
return head->attr.st_size;
7174

7275
while(now != NULL) {
7376
size += now->size;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /