main.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. )
  6. func check(e error) {
  7. if e != nil {
  8. panic(e)
  9. }
  10. }
  11. func init() {
  12. setting, err := os.Create("setting.config")
  13. check(err)
  14. defer setting.Close()
  15. setting.WriteString("")
  16. setting.Sync()
  17. }
  18. func file_exists(filepath string) bool {
  19. if _, err := os.Stat(filepath); !os.IsNotExist(err) {
  20. return true
  21. }
  22. return false
  23. }
  24. func mkdir(filepath string){
  25. os.MkdirAll(filepath, os.ModePerm)
  26. }
  27. func file_put_contents(file string, data string) bool{
  28. f, err := os.Create(file)
  29. check(err)
  30. _, err = f.WriteString(data)
  31. defer f.Close()
  32. if (err != nil){
  33. return false
  34. }
  35. return true
  36. }
  37. func main() {
  38. //arozdfs implementation in Golang
  39. /*
  40. Supported commands:
  41. help --> show all the help information
  42. init --> initiate the arozdfs structure according to setup.config
  43. [Uploading to arozdfs commands]
  44. upload
  45. -infile <filename> --> declare the input file
  46. -storepath <pathname> --> Relative path from the arozdfs root
  47. -slice <filesize> --> declare the slicing filesize
  48. -push <clusterlist.config> --> push to a list of clusters and sync file index to other clusters
  49. [Download from arozdfs commands]
  50. download
  51. -outfile <file.index> --> rebuild a file from cluster storage to local drive
  52. [File Operations]
  53. remove <file.index> --> remove all chunks related to thie file index
  54. rename <file.index> <newfile.index> --> rename all records related to this file
  55. move <filepath/file.index> <newpath/file.index> --> move the file to a new path in index directory
  56. [System checking commands]
  57. checkfile <file.index> --> check if a file contains all chunks which has at least two copies of each chunks
  58. rebuild --> Check all files on the system and fix all chunks which has corrupted
  59. migrate <host-uuid>
  60. */
  61. for i, arg := range os.Args {
  62. // print index and value
  63. fmt.Println("item", i, "is", arg)
  64. }
  65. //Check if the required directory exists. If not, create it.
  66. if (!file_exists("chunks/")){
  67. mkdir("chunks/")
  68. }
  69. if (!file_exists("uploads/")){
  70. mkdir("uploads/")
  71. }
  72. file_put_contents("Hello World.txt","This is the content of the file.")
  73. }