sync v0.1 will sync files/directory from a source folder to destination folder. It is dumb, there is no diff check. this is for accelbyte technical test
make
or
go build -o ./bin/sync main.go
Quiet Run (Default):
./bin/sync -d [destination_folder] -s [source_folder]
Verbose Run:
./bin/sync -v -d [destination_folder] -s [source_folder]
Create empty folder:
./bin/sync -e -d [destination_folder] -s [source_folder]
Help:
./bin/sync
I follow the reference[1] regarding pipeline. Basically there are 2 channels which being used to connect 3 processes.
- First is a walker process which walks recursively the source folder. In this process list of files are sent to the 2nd level, if it is folder, it checks if it exists in destination folder, if not, it will create one.
- Second is file validator, which validates if the file received from walker (level 1) is valid for processing, if valid then it will pass to next level. Valid here means the file not exist or differ with destination folder
- Third level is copying the file from source to destination, where the source path is received from file validater (level 2)
If canceled (by ctrl C) or during process it will stop the current process immediately.
- I think this program could be improved by using goroutine when reading 2 files and computing the md5sum simultaneously
- I only compiled and test using MacOS monterey on M1