|
| 1 | +package common |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | +) |
| 7 | + |
| 8 | +type Diffs struct { |
| 9 | + Dummy string `json:"dummy"` // TODO: This is only used for debugging purposes and needs to be removed later |
| 10 | +} |
| 11 | + |
| 12 | +// Diff |
| 13 | +func Diff(ownerA string, folderA string, nameA string, commitA string, ownerB string, folderB string, nameB string, commitB string, loggedInUser string) (Diffs, error) { |
| 14 | + // Check if the user has access to the requested databases |
| 15 | + bucketA, idA, _, err := MinioLocation(ownerA, folderA, nameA, commitA, loggedInUser) |
| 16 | + if err != nil { |
| 17 | + return Diffs{}, err |
| 18 | + } |
| 19 | + bucketB, idB, _, err := MinioLocation(ownerB, folderB, nameB, commitB, loggedInUser) |
| 20 | + if err != nil { |
| 21 | + return Diffs{}, err |
| 22 | + } |
| 23 | + |
| 24 | + // Sanity check |
| 25 | + if idA == "" { |
| 26 | + // The requested database wasn't found, or the user doesn't have permission to access it |
| 27 | + err = fmt.Errorf("Requested database not found") |
| 28 | + log.Printf("Requested database not found: '%s%s%s'", ownerA, folderA, nameA) |
| 29 | + return Diffs{}, err |
| 30 | + } |
| 31 | + if idB == "" { |
| 32 | + // The requested database wasn't found, or the user doesn't have permission to access it |
| 33 | + err = fmt.Errorf("Requested database not found") |
| 34 | + log.Printf("Requested database not found: '%s%s%s'", ownerB, folderB, nameB) |
| 35 | + return Diffs{}, err |
| 36 | + } |
| 37 | + |
| 38 | + // Retrieve database files from Minio, using locally cached version if it's already there |
| 39 | + dbA, err := RetrieveDatabaseFile(bucketA, idA) |
| 40 | + if err != nil { |
| 41 | + return Diffs{}, err |
| 42 | + } |
| 43 | + dbB, err := RetrieveDatabaseFile(bucketB, idB) |
| 44 | + if err != nil { |
| 45 | + return Diffs{}, err |
| 46 | + } |
| 47 | + |
| 48 | + // Call dbDiff which does the actual diffing of the database files |
| 49 | + return dbDiff(dbA, dbB) |
| 50 | +} |
| 51 | + |
| 52 | +// dbDiff |
| 53 | +func dbDiff(dbA string, dbB string) (Diffs, error) { |
| 54 | + var diff Diffs |
| 55 | + |
| 56 | + // Check if this is the same database and exit early |
| 57 | + if dbA == dbB { |
| 58 | + diff.Dummy = "same dbs" |
| 59 | + return diff, nil |
| 60 | + } |
| 61 | + |
| 62 | + // TODO |
| 63 | + diff.Dummy = "different dbs" |
| 64 | + |
| 65 | + // Return |
| 66 | + return diff, nil |
| 67 | +} |
0 commit comments