Jump to content

Rebol Programming/exists-thru?

From Wikibooks, open books for an open world

USAGE:

[edit | edit source]
EXISTS-THRU? url /check info 

DESCRIPTION:

[edit | edit source]

Checks if a file is in the disk cache. Returns: none, false (out of date), or file

EXISTS-THRU? is a function value.

ARGUMENTS

[edit | edit source]
  • url -- (Type: url file)

REFINEMENTS

[edit | edit source]
  • /check -- Checks version, checksum/secure, date, and/or size of cached file.
    • info -- (Type: block tuple binary logic date none)

SOURCE CODE

[edit | edit source]
exists-thru?: func [
    {Checks if a file is in the disk cache. Returns: none, false (out of date), or file} 
    url [url! file!] 
    /check {Checks version, checksum/secure, date, and/or size of cached file.} 
    info [block! tuple! binary! logic! date! none!] 
    /local file data date
][
    if not file: path-thru url [return none] 
    if not exists? file [return false] 
    if not check [return file] 
    if none? info [return file] 
    if tuple? info [
        if not data: attempt [load/header script? file] [return none] 
        if all [
            object? data: data/1 
            tuple? data/version 
            data/version >= info
        ] [return file] 
        return false
    ] 
    if binary? info [
        if not data: attempt [read/binary file] [return none] 
        if info = checksum/secure data [return file] 
        return false
    ] 
    if not block? info [info: reduce [info]] 
    foreach item info [
        if date? item [
            date: get-modes file 'modification-date 
            if (date + 0:00:03) < item [return false]
        ] 
        if integer? item [
            if item <> size? file [return false]
        ]
    ] 
    file
]