jcanfield
6/3/2012 - 7:11 PM

Create Hardlinks to Sync Folders with Google Drive

Create Hardlinks to Sync Folders with Google Drive

/*** 
Synopsis: One of two viable options I have found to create hard-links of directories from other directories on your system directly to Google Drive has been hardlink.c (by Sam, @selkhateeb on Github) and a Mac OSX Application called SymbolicLinker. SymbolicLinker can be found at http://seiryu.home.comcast.net/~seiryu/symboliclinker.html as-well as http://www.macupdate.com/app/mac/10433/symboliclinker. Now, you can sync specific folders to your Google Drive since that GDrive does not allow for actual symbolic links (ln -s) to create files that will be uploaded to the "cloud".

Application: hardlink
URL: https://github.com/selkhateeb/hardlink
Author: Sam (@selkhateeb)
Description: Allows for the user to create hardlinks of directories.
Installation: 1) make 2) sudo make install
Usage: hardlink /home/username/foldername/ /home/username/Documents/Cloud/foldername/
***/

#include <unistd.h>
#include <stdio.h>
#include <string.h>
/*
On Mac OSX, we can't create hard links using the ln command..

Install:
 make
 sudo make install
*/
int main(int argc, char* argv[]) {
    //Make sure we have the right arguments
    if (argc != 3)
    {
        fprintf(stderr,"Usage:\thardlink source destination\n");
        fprintf(stderr,"\t  hard links the source directory to the destination\n");
        fprintf(stderr,"\thardlink -u destination\n");
        fprintf(stderr,"\t  unlinks the destination directoy\n");
        return 1;
    }
    int ret = 0;
    if(strcmp(argv[1], "-u") == 0)
    {
        ret = unlink(argv[2]);
    }
    else
        ret = link(argv[1],argv[2]);
    
    if (ret != 0)
        perror("hardlink");
    return ret;
} 
OUTPUT=hardlink
C_FILES=hardlink.c

all:
	gcc ${C_FILES} -o ${OUTPUT}

clean:
	rm ${OUTPUT}

install:
	cp ${OUTPUT} /usr/local/bin/