Commit 0bdf3cb9 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

fixes for sync

parent 5d06f28b
......@@ -215,37 +215,40 @@
;; redundant second pass to syncronise files - independant of the
;; rest of the syncing system
(define (sync-files server-list)
(let ((local-files (dir-list "/sdcard/symbai/files/")))
(let ((local-list (dir-list "/sdcard/symbai/files/")))
;; search for all local files in server list
(lambda (file r)
;; send files not present
(if (find file server-list)
(if (in-list? file server-list)
r (cons
(string-append "upload-" file)
(string-append "/sdcard/symbai/files/" file)) r)))
;; search for all server files in local list
(lambda (file r)
;; request files not present
(if (find file local-list)
(if (in-list? file local-list)
r (cons
(string-append "download-" file)
(string-append "" file)
(string-append "/sdcard/symbai/files/" file)) r)))
(define (start-sync-files)
(string-append "file-list")
(string-append url "fn=file-list")
(lambda (file-list)
(sync-files file-list))))
(string-append "file-list")
(string-append url "fn=file-list")
(lambda (file-list)
(sync-files file-list)))))
;; spit all dirty entities to server
(define (spit db table entities)
......@@ -353,13 +356,14 @@
(define (mark-unlisted-entities-dirty! db table version-data)
(msg "mark-unlisted...")
;; load all local entities
(let ((ids (all-unique-ids db table))
(server-ids (map car version-data)))
;; look for each one in data
(lambda (id)
(when ((not (find id server-ids)))
(when (not (in-list? id server-ids))
(msg "can't find " id " in server data, marking dirty")
;; mark those not present as dirty for next spit cycle
(update-entity-dirtify db table id)))
......@@ -60,6 +60,12 @@
(else (_ (cdr in) (cons (cons (car in) (car out)) (cdr out)) (- c 1)))))
(reverse (map reverse (_ l '(()) n))))
(define (in-list? n l)
((null? l) #f)
((equal? n (car l)) #t)
(else (in-list? n (cdr l)))))
(define (find n l)
((null? l) #f)
......@@ -71,10 +71,9 @@
((null? vd) r)
;; only return if dirty
((zero? (cadr vd))
((not (zero? (cadr vd)))
(list (ktv-key kt) (ktv-type kt) (list-ref vd 0))
(list (ktv-key kt) (ktv-type kt) (list-ref vd 0)) r))
(else r)))
db table entity-id))
......@@ -77,7 +77,6 @@
;; build according to url ([table] entity-type unique-id dirty version)
(cdr (vector->list i))
;; data entries (todo - only dirty values!)
(get-entity-plain-for-sync db table (vector-ref i 0))))
(cdr de)))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment