Skip to content

bondhan/sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sync

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

Compile

make

or

go build -o ./bin/sync main.go

Run

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

Under the skin

syncdrawio.png

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.

Limitation and Improvement

  • 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

Author

bondhan_novandy@gmail.com

References

  1. pipelines