code_junkie

RAMDrive for compiling - is there such a thing?

Nov 12th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. # setup locations
  2. $ramdrive = /Volumes/ramspace
  3. $project = $HOME/code/someproject
  4.  
  5. # ..create ram drive..
  6.  
  7. # sync project directory to RAM drive
  8. rsync -av $project $ramdrive
  9.  
  10. # build
  11. cd $ramdrive
  12. make
  13.  
  14. #optional, copy the built data to the project directory:
  15. rsync $ramdrive/build $project/build
  16.  
  17. # may need some error checking for bad input.
  18.  
  19. #convert relative path to absolute
  20. # /bin/pwd gets real path without symbolic link on my system and pwd
  21. # keeps symbolic link. may need to change to suit your needs
  22. somedir=`cd $1; /bin/pwd`;
  23. somedirparent=`dirname $somedir`
  24.  
  25. # backup directory
  26. /bin/tar cf $somedir.tar $somedir
  27.  
  28. # copy, tried move like https://wiki.archlinux.org/index.php/Ramdisk
  29. # suggests, but got error
  30. mkdir -p /mnt/ramdisk$somedir
  31. /bin/cp -r $somedir /mnt/ramdisk$somedirparent
  32.  
  33. # remove dir
  34. /bin/rm -r $somedir
  35.  
  36. # create symbolic link. needs to be in parent of given foler.
  37. /bin/ln -s /mnt/ramdisk$somedir $somedirparent
  38.  
  39. #run updater
  40. ~/bin/rdbackupd "/bin/tar -uf $somedir.tar $somedir" &
  41.  
  42. #!/bin/bash
  43.  
  44. #convert relative path to absolute
  45. #somepath would probably make more sense
  46. # pwd and not /bin/pwd so we get symbolic path
  47. somedir=`cd $1; pwd`;
  48.  
  49. # remove symbolic link
  50. rm $somedir
  51.  
  52. # copy dir back
  53. /bin/cp -r /mnt/ramdisk$somedir $somedir
  54.  
  55. #remove from ramdisk
  56. /bin/rm -r /mnt/ramdisk$somedir
  57.  
  58. #stop
  59. killall rdbackupd
  60.  
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. #include <time.h>
  64. #include <signal.h>
  65. #include <sys/time.h>
  66.  
  67. struct itimerval it;
  68. char* command;
  69.  
  70. void update_archive(int sig)
  71. {
  72. system(command);
  73. }
  74.  
  75. int main(int argc, char**argv)
  76. {
  77. it.it_value.tv_sec = 1; // start right now
  78. it.it_value.tv_usec = 0;
  79. it.it_interval.tv_sec = 60; // run every 60 seconds
  80. it.it_interval.tv_usec = 0;
  81.  
  82. if (argc < 2)
  83. {
  84. printf("rdbackupd: Need command to runn");
  85. return 1;
  86. }
  87. command = argv[1];
  88.  
  89. signal(SIGALRM, update_archive);
  90. setitimer(ITIMER_REAL, &it, NULL); // start
  91.  
  92. while(true);
  93.  
  94. return 0;
  95. }
Add Comment
Please, Sign In to add comment