Skip to content

Commit adeed6a

Browse files
committed
complete ssu_rsync
1 parent 220d4e4 commit adeed6a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef COMMON_H
77
#define COMMON_H
88

9-
#define DEBUG
9+
//#define DEBUG
1010

1111
#include <stdio.h>
1212
#include <stdlib.h>

ssu_rsync.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ void renewal(int count) // 파일 동기화
488488
struct utimbuf attr;
489489
size_t length;
490490

491+
491492
for (int i = 0; i < count; i++) {
492493

493494
switch (change_list[i].status) {
@@ -506,7 +507,10 @@ void renewal(int count) // 파일 동기화
506507
memset(path, 0, MAX_BUFFER_SIZE);
507508

508509
lstat(change_list[i].name, &statbuf);
509-
sprintf(path, "%.*s/%s", (int)strlen(dst_path), dst_path, change_list[i].name + strlen(src_path) + 1); // 동기화 파일 경로 생성
510+
if (src_is_dir)
511+
sprintf(path, "%s/%s", dst_path, change_list[i].name + strlen(src_path) + 1); // 동기화된 파일 경로 생성
512+
else
513+
sprintf(path, "%s/%s", dst_path, change_list[i].name + strlen(src_path) - strlen(get_file_name(src_path))); // 동기화된 파일 경로 생성
510514
#ifdef DEBUG
511515
printf("renewal: path = %s\n", path);
512516
#endif
@@ -721,8 +725,9 @@ void free_list(file_node *head) // 모니터링 파일 목록 메모리 할당
721725
*/
722726
void recovery(int signo) // SIGINT 시그널 처리
723727
{
724-
char command[MAX_BUFFER_SIZE];
725-
char path[MAX_BUFFER_SIZE];
728+
char file_name[BUFFER_SIZE] = { 0 };
729+
char command[MAX_BUFFER_SIZE] = { 0 };
730+
char path[MAX_BUFFER_SIZE] = { 0 };
726731

727732
if(signo == SIGINT) { // SIGINT 시그널 획득 시
728733
#ifdef DEBUG
@@ -737,15 +742,16 @@ void recovery(int signo) // SIGINT 시그널 처리
737742
#endif
738743
chdir(path);
739744

745+
sprintf(file_name, "%s.swp", get_file_name(dst_path));
740746
#ifdef DEBUG
741-
sprintf(command, "tar -xvf %s.swp", get_file_name(dst_path)); // 복원 명령어 생성(압축 해제)
747+
sprintf(command, "tar -xvf %s", file_name); // 복원 명령어 생성(압축 해제)
742748
printf("recovery(): command = %s\n", command);
743749
#else
744-
sprintf(command, "tar -xf %s.swp", get_file_name(dst_path)); // 복원 명령어 생성(압축 해제)
750+
sprintf(command, "tar -xf %s", file_name); // 복원 명령어 생성(압축 해제)
745751
#endif
746752
remove_directory(dst_path); // 기존 동기화 디렉토리 삭제
747753
system(command); // 복원 명령어 실행
748-
unlink(command + 9); // swap 파일 삭제
754+
unlink(file_name); // swap 파일 삭제
749755

750756
}
751757
exit(1);

0 commit comments

Comments
 (0)