Closed marcows closed 5 years ago
Thanks for the feedback. I have fixed this by saving the working directory and then restoring it afterwards. I've also dynamically allocated the buffer for the directory name, after working out how long it will be, to fix the buffer overflow issue.
When setting a non-default activity store with a relative path, downloading activities saves each succeeding ttbin file one directory hierarchy deeper.
Reproduce: $ cd $HOME $ ttwatch --activity-store=customstore --get-activities
If downloading 3 activities, they are stored as follows: /home/markus/customstore/watchname/2018-11-03/Running_11-11-35.ttbin /home/markus/customstore/watchname/2018-11-03/customstore/watchname/2018-11-03/Running_11-22-21.ttbin /home/markus/customstore/watchname/2018-11-03/customstore/watchname/2018-11-03/customstore/watchname/2018-11-03/Running_11-45-41.ttbin
Reason is using chdir() with a relative path in do_get_activities_callback() which is called for each ttbin file.
Solutions could be 1) Avoiding chdir() and prepending the directory name to the file name. 2) Converting the activity store to an absolute path as it is already done for the default $HOME/ttwatch.
I also noticed that using strcpy() in do_get_activities_callback() causes a buffer overflow if using 256 or more characters for the activity store, leading to a segmentation fault for me.