@@ -211,15 +211,15 @@ void syncronize(char *src_path, char *dst_path) // 동기화 함수
211
211
compare_list (src_list -> child , dst_list -> child );
212
212
is_directory = true;
213
213
} else // 타겟이 파일일 경우
214
- compare_file (src_list , dst_list -> child , true );
214
+ compare_file (src_list , dst_list -> child );
215
215
216
216
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 ); // 생성 혹은 수정된 파일 확인
218
218
else
219
- change_count = write_change_list (src_list , change_count , CREATE ); // 생성 혹은 수정된 파일 확인
219
+ change_count = write_change_list (src_list , change_count , CREATE , true ); // 생성 혹은 수정된 파일 확인
220
220
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 ); // 삭제 혹은 수정된 파일 확인
223
223
224
224
free_list (src_list );
225
225
free_list (dst_list );
@@ -340,9 +340,8 @@ void compare_list(file_node *src_list, file_node *dst_list) // 파일 목록 트
340
340
341
341
while (now != NULL ) { // 타겟 파일 탐색
342
342
343
- compare_file (now , dst_list , true );
343
+ compare_file (now , dst_list );
344
344
345
- if (option_r ) // R 옵션이 존재하는 경우
346
345
if (now -> child != NULL )
347
346
compare_list (now -> child , dst_list );
348
347
@@ -354,10 +353,9 @@ void compare_list(file_node *src_list, file_node *dst_list) // 파일 목록 트
354
353
* @brief 파일 정보 비교
355
354
* @param src_file 타겟 파일 노드
356
355
* @param dst_file 동기화 디렉토리 파일 노드
357
- * @param is_first 첫번째 레벨 확인 변수
358
356
* @return 비교 성공 유무
359
357
*/
360
- bool compare_file (file_node * src_file , file_node * dst_file , bool is_first ) // 파일 정보 비교
358
+ bool compare_file (file_node * src_file , file_node * dst_file ) // 파일 정보 비교
361
359
{
362
360
file_node * now ;
363
361
@@ -368,21 +366,24 @@ bool compare_file(file_node *src_file, file_node *dst_file, bool is_first) //
368
366
#ifdef DEBUG
369
367
printf ("compare_file(): src_file->name = %s, dst_file->name = %s\n" , src_file -> name + strlen (pwd ) + 1 , now -> name + strlen (pwd ) + 1 );
370
368
#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 )) { // 파일 이름이 같은 경우
372
370
373
371
#ifdef DEBUG
374
372
printf ("compare_file(): file found\n" );
375
373
#endif
376
374
src_file -> status = CHCKED ;
377
375
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. 수정시간이 다를 경우
379
382
#ifdef DEBUG
380
383
printf ("compare_file(): mtime different\n" );
381
384
#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. 크기가 다를 경우
386
387
387
388
#ifdef DEBUG
388
389
printf ("compare_file(): size different\n" );
@@ -397,9 +398,8 @@ bool compare_file(file_node *src_file, file_node *dst_file, bool is_first) //
397
398
return true;
398
399
}
399
400
400
- if (option_r || is_first )
401
401
if (now -> child != NULL ) // 디렉토리 안에 파일이 존재할 경우
402
- if (compare_file (src_file , now -> child , false ))
402
+ if (compare_file (src_file , now -> child ))
403
403
break ;
404
404
405
405
now = now -> next ;
@@ -413,8 +413,9 @@ bool compare_file(file_node *src_file, file_node *dst_file, bool is_first) //
413
413
* @param head 트리 루트 노드
414
414
* @param idx 변경사항 목록 시작 인덱스
415
415
* @param status 변경 사항 타입 번호
416
+ * @param is_first 첫번째 레벨 확인 변수
416
417
*/
417
- int write_change_list (file_node * head , int idx , int status ) // 변경사항 목록 작성
418
+ int write_change_list (file_node * head , int idx , int status , bool is_first ) // 변경사항 목록 작성
418
419
{
419
420
file_node * now ;
420
421
@@ -426,11 +427,13 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
426
427
case UNCHCK :
427
428
if (status == CREATE ) { // 생성됨
428
429
strcpy (change_list [idx ].name , now -> name );
429
- //strcpy(change_list[idx].name, now->name + strlen(src_path) + 1);
430
430
change_list [idx ].status = CREATE ;
431
431
} 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 ;
432
436
strcpy (change_list [idx ].name , now -> name );
433
- //strcpy(change_list[idx].name, now->name + strlen(dst_path) + 1);
434
437
change_list [idx ].status = DELETE ;
435
438
}
436
439
change_list [idx ++ ].size = now -> size ;
@@ -441,7 +444,6 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
441
444
442
445
case MODIFY : // 수정됨
443
446
strcpy (change_list [idx ].name , now -> name );
444
- //strcpy(change_list[idx].name, now->name + strlen(src_path) + 1);
445
447
change_list [idx ].status = MODIFY ;
446
448
change_list [idx ++ ].size = now -> size ;
447
449
#ifdef DEBUG
@@ -450,9 +452,9 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
450
452
break ;
451
453
}
452
454
453
- if (option_r )
455
+ if (option_r || is_first )
454
456
if (now -> child != NULL )
455
- idx = write_change_list (now -> child , idx , status );
457
+ idx = write_change_list (now -> child , idx , status , false );
456
458
457
459
now = now -> next ;
458
460
}
0 commit comments