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 d73fc53

Browse files
committed
fix bug ssu_rsync option m, r
1 parent 02ef1ba commit d73fc53

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

‎1.c

Whitespace-only changes.

‎ssu_rsync.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ void syncronize(char *src_path, char *dst_path) // 동기화 함수
211211
compare_list(src_list->child, dst_list->child);
212212
is_directory = true;
213213
} else // 타겟이 파일일 경우
214-
compare_file(src_list, dst_list->child, true);
214+
compare_file(src_list, dst_list->child);
215215

216216
if (is_directory)
217-
change_count = write_change_list(src_list->child, change_count, CREATE); // 생성 혹은 수정된 파일 확인
217+
change_count = write_change_list(src_list->child, change_count, CREATE, true); // 생성 혹은 수정된 파일 확인
218218
else
219-
change_count = write_change_list(src_list, change_count, CREATE); // 생성 혹은 수정된 파일 확인
219+
change_count = write_change_list(src_list, change_count, CREATE, true); // 생성 혹은 수정된 파일 확인
220220

221-
if (option_m)
222-
change_count = write_change_list(dst_list, change_count, DELETE); // 삭제 혹은 수정된 파일 확인
221+
if (option_m)
222+
change_count = write_change_list(dst_list->child, change_count, DELETE, true); // 삭제 혹은 수정된 파일 확인
223223

224224
free_list(src_list);
225225
free_list(dst_list);
@@ -340,9 +340,8 @@ void compare_list(file_node *src_list, file_node *dst_list) // 파일 목록 트
340340

341341
while (now != NULL) { // 타겟 파일 탐색
342342

343-
compare_file(now, dst_list, true);
343+
compare_file(now, dst_list);
344344

345-
if (option_r) // R 옵션이 존재하는 경우
346345
if (now->child != NULL)
347346
compare_list(now->child, dst_list);
348347

@@ -354,10 +353,9 @@ void compare_list(file_node *src_list, file_node *dst_list) // 파일 목록 트
354353
* @brief 파일 정보 비교
355354
* @param src_file 타겟 파일 노드
356355
* @param dst_file 동기화 디렉토리 파일 노드
357-
* @param is_first 첫번째 레벨 확인 변수
358356
* @return 비교 성공 유무
359357
*/
360-
bool compare_file(file_node *src_file, file_node *dst_file, boolis_first) // 파일 정보 비교
358+
bool compare_file(file_node *src_file, file_node *dst_file) // 파일 정보 비교
361359
{
362360
file_node *now;
363361

@@ -368,21 +366,24 @@ bool compare_file(file_node *src_file, file_node *dst_file, bool is_first) //
368366
#ifdef DEBUG
369367
printf("compare_file(): src_file->name = %s, dst_file->name = %s\n", src_file->name + strlen(pwd) + 1, now->name + strlen(pwd) + 1);
370368
#endif
371-
if (!strcmp(src_file->name + strlen(pwd) + 1, now->name + strlen(dst_path) + 1)) { // 해당 이름을 가진 파일이 기존에 이미 존재할 경우
369+
if (!strcmp(src_file->name + strlen(pwd) + 1, now->name + strlen(dst_path) + 1)) { // 파일 이름이 같은 경우
372370

373371
#ifdef DEBUG
374372
printf("compare_file(): file found\n");
375373
#endif
376374
src_file->status = CHCKED;
377375

378-
if (src_file->attr.st_mtime != now->attr.st_mtime) { // 해당 파일이 수정되었을 경우
376+
if (src_file->attr.st_mode != now->attr.st_mode) { // 1. 파일 형식이 다를 경우
377+
#ifdef DEBUG
378+
printf("compare_file(): type different\n");
379+
#endif
380+
src_file->status = MODIFY;
381+
} else if (src_file->attr.st_mtime != now->attr.st_mtime) { // 2. 수정시간이 다를 경우
379382
#ifdef DEBUG
380383
printf("compare_file(): mtime different\n");
381384
#endif
382-
src_file->status = MODIFY; // 타겟 파일의 상태 변경
383-
}
384-
385-
if (src_file->size != now->size) { // 해당 파일의 크기가 변경되었을 경우
385+
src_file->status = MODIFY;
386+
} else if (src_file->size != now->size) { // 3. 크기가 다를 경우
386387

387388
#ifdef DEBUG
388389
printf("compare_file(): size different\n");
@@ -397,9 +398,8 @@ bool compare_file(file_node *src_file, file_node *dst_file, bool is_first) //
397398
return true;
398399
}
399400

400-
if(option_r || is_first)
401401
if(now->child != NULL) // 디렉토리 안에 파일이 존재할 경우
402-
if(compare_file(src_file, now->child, false))
402+
if(compare_file(src_file, now->child))
403403
break;
404404

405405
now = now->next;
@@ -413,8 +413,9 @@ bool compare_file(file_node *src_file, file_node *dst_file, bool is_first) //
413413
* @param head 트리 루트 노드
414414
* @param idx 변경사항 목록 시작 인덱스
415415
* @param status 변경 사항 타입 번호
416+
* @param is_first 첫번째 레벨 확인 변수
416417
*/
417-
int write_change_list(file_node *head, int idx, int status) // 변경사항 목록 작성
418+
int write_change_list(file_node *head, int idx, int status, boolis_first) // 변경사항 목록 작성
418419
{
419420
file_node *now;
420421

@@ -426,11 +427,13 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
426427
case UNCHCK:
427428
if (status == CREATE) { // 생성됨
428429
strcpy(change_list[idx].name, now->name);
429-
//strcpy(change_list[idx].name, now->name + strlen(src_path) + 1);
430430
change_list[idx].status = CREATE;
431431
} else if (status == DELETE) { // 삭제됨
432+
char tmp[MAX_BUFFER_SIZE];
433+
sprintf(tmp, "%s/%s", dst_path, get_file_name(src_path));
434+
if(strstr(now->name, tmp) == NULL || !strcmp(now->name, tmp))
435+
break;
432436
strcpy(change_list[idx].name, now->name);
433-
//strcpy(change_list[idx].name, now->name + strlen(dst_path) + 1);
434437
change_list[idx].status = DELETE;
435438
}
436439
change_list[idx++].size = now->size;
@@ -441,7 +444,6 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
441444

442445
case MODIFY: // 수정됨
443446
strcpy(change_list[idx].name, now->name);
444-
//strcpy(change_list[idx].name, now->name + strlen(src_path) + 1);
445447
change_list[idx].status = MODIFY;
446448
change_list[idx++].size = now->size;
447449
#ifdef DEBUG
@@ -450,9 +452,9 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
450452
break;
451453
}
452454

453-
if(option_r)
455+
if(option_r||is_first)
454456
if (now->child != NULL)
455-
idx = write_change_list(now->child, idx, status);
457+
idx = write_change_list(now->child, idx, status, false);
456458

457459
now = now->next;
458460
}

‎ssu_rsync.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ file_node *make_node(void); // 노드 생성
4747
file_node *make_list(char *path); // 디렉토리 파일 목록 트리화
4848
int count_size(file_node *head); // 디렉토리 크기 반환
4949
void compare_list(file_node *src_list, file_node *dst_list); // 파일 목록 트리 비교
50-
bool compare_file(file_node *src_file, file_node *dst_file, boolis_first); // 파일 정보 비교
51-
int write_change_list(file_node *head, int idx, int status); // 변경사항 목록 작성
50+
bool compare_file(file_node *src_file, file_node *dst_file); // 파일 정보 비교
51+
int write_change_list(file_node *head, int idx, int status, boolis_first); // 변경사항 목록 작성
5252
void free_list(file_node *head); // 모니터링 파일 목록 메모리 할당 해제
5353
void recovery(int signo); // SIGINT 시그널 처리
5454
void remove_directory(const char *path); // 디렉토리 삭제

0 commit comments

Comments
(0)

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