Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.5 KiB

  1. package main
  2. import (
  3. "time"
  4. "github.com/dustin/go-humanize"
  5. )
  6. var defaultExpiryList = []uint64{
  7. 60,
  8. 300,
  9. 3600,
  10. 86400,
  11. 604800,
  12. 2419200,
  13. 31536000,
  14. }
  15. type ExpirationTime struct {
  16. Seconds uint64
  17. Human string
  18. }
  19. var neverExpire = time.Unix(0, 0)
  20. // Determine if a file with expiry set to "ts" has expired yet
  21. func isTsExpired(ts time.Time) bool {
  22. now := time.Now()
  23. return ts != neverExpire && now.After(ts)
  24. }
  25. // Determine if the given filename is expired
  26. func isFileExpired(filename string) (bool, error) {
  27. metadata, err := metadataRead(filename)
  28. if err != nil {
  29. return false, err
  30. }
  31. return isTsExpired(metadata.Expiry), nil
  32. }
  33. // Return a list of expiration times and their humanized versions
  34. func listExpirationTimes() []ExpirationTime {
  35. epoch := time.Now()
  36. actualExpiryInList := false
  37. var expiryList []ExpirationTime
  38. for _, expiry := range defaultExpiryList {
  39. if Config.maxExpiry == 0 || expiry <= Config.maxExpiry {
  40. if expiry == Config.maxExpiry {
  41. actualExpiryInList = true
  42. }
  43. duration := time.Duration(expiry) * time.Second
  44. expiryList = append(expiryList, ExpirationTime{
  45. expiry,
  46. humanize.RelTime(epoch, epoch.Add(duration), "", ""),
  47. })
  48. }
  49. }
  50. if Config.maxExpiry == 0 {
  51. expiryList = append(expiryList, ExpirationTime{
  52. 0,
  53. "never",
  54. })
  55. } else if actualExpiryInList == false {
  56. duration := time.Duration(Config.maxExpiry) * time.Second
  57. expiryList = append(expiryList, ExpirationTime{
  58. Config.maxExpiry,
  59. humanize.RelTime(epoch, epoch.Add(duration), "", ""),
  60. })
  61. }
  62. return expiryList
  63. }