Browse Source

Update session modify time on read, every 30 minute to prevent deleting

Vova Tkach 6 years ago
parent
commit
b0d9f0676c
1 changed files with 7 additions and 0 deletions
  1. 7 0
      session/session.go

+ 7 - 0
session/session.go

@@ -40,6 +40,13 @@ func New(w http.ResponseWriter, r *http.Request, tmpdir string) *Session {
 			if err == nil {
 				return &sess
 			}
+
+			// Update file last modify time if needs
+			if info, err := os.Stat(sess.d + string(os.PathSeparator) + sess.i); err == nil {
+				if time.Now().Sub(info.ModTime()) > 30 * time.Minute {
+					_ = os.Chtimes(sess.d + string(os.PathSeparator) + sess.i, time.Now(), time.Now())
+				}
+			}
 		}
 	} else {
 		// Create new