Diff

Differences From Artifact [25e6dbc0f2]:

To Artifact [6f6d010e1e]:


476
477
478
479
480
481
482





483
484
485
486
487
488
489
...
522
523
524
525
526
527
528

529
530
531
532
533
534
535
...
580
581
582
583
584
585
586




587
588
589
590
591
592
593
594
595
596
597
598
599
600


601





602




603
604
605
606
607
608
609

		return -code error "Invalid or unacceptable path: $dir"
	}

	proc getattr {path} {
		array set pathinfo [_parsepath $path]
		array set retval [list]






		switch -- $pathinfo(_type) {
			"toplevel" {
				set retval(type) directory
				set retval(childcount) 2;
			}
			"sites" {
................................................................................
					if {[info exists pathinfo(package_sha1)] && $pathinfo(package_sha1) != ""} {
						set retval(type) directory
						set retval(childcount) 2;
					}
				}
			}
			"files" {

				set retval(packaged) 1

				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
				if {[file exists $localpath]} {
					catch {
						file lstat $localpath localpathinfo
						set retval(time) $localpathinfo(mtime)
................................................................................
		}

		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]

		if {[file exists $localpath]} {
			return $localpath
		}





		set work [split $pathinfo(file) "/"]
		set directory [join [lrange $work 0 end-1] "/"]
		set file [lindex $work end]
		set file_sha1 [::appfs::db onecolumn {SELECT file_sha1 FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_name = $file AND file_directory = $directory;}]

		if {$file_sha1 == ""} {
			return -code error "No such file or directory"
		}

		set localcachefile [download $pathinfo(hostname) $file_sha1]

		if {$mode == "create"} {
			set tmplocalpath "${localpath}.[expr rand()][clock clicks]"


			file copy -force -- $localcachefile $tmplocalpath





			file rename -force -- $tmplocalpath $localpath





			return $localpath
		}

		return $localcachefile
	}
}







>
>
>
>
>







 







>







 







>
>
>
>




|

|



|

|

>
>
|
>
>
>
>
>
|
>
>
>
>







476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

		return -code error "Invalid or unacceptable path: $dir"
	}

	proc getattr {path} {
		array set pathinfo [_parsepath $path]
		array set retval [list]

		catch {
			::appfs::getindex $pathinfo(hostname)
			::appfs::getpkgmanifest $pathinfo(hostname) $pathinfo(package_sha1)
		}

		switch -- $pathinfo(_type) {
			"toplevel" {
				set retval(type) directory
				set retval(childcount) 2;
			}
			"sites" {
................................................................................
					if {[info exists pathinfo(package_sha1)] && $pathinfo(package_sha1) != ""} {
						set retval(type) directory
						set retval(childcount) 2;
					}
				}
			}
			"files" {

				set retval(packaged) 1

				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
				if {[file exists $localpath]} {
					catch {
						file lstat $localpath localpathinfo
						set retval(time) $localpathinfo(mtime)
................................................................................
		}

		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]

		if {[file exists $localpath]} {
			return $localpath
		}

		if {$mode == "create"} {
			return $localpath
		}

		set work [split $pathinfo(file) "/"]
		set directory [join [lrange $work 0 end-1] "/"]
		set file [lindex $work end]
		::appfs::db eval {SELECT file_sha1, perms FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_name = $file AND file_directory = $directory;} pkgpathinfo {}

		if {$pkgpathinfo(file_sha1) == ""} {
			return -code error "No such file or directory"
		}

		set localcachefile [download $pathinfo(hostname) $pkgpathinfo(file_sha1)]

		if {$mode == "write"} {
			set tmplocalpath "${localpath}.[expr rand()][clock clicks]"

			catch {
				file copy -force -- $localcachefile $tmplocalpath

				if {$pkgpathinfo(perms) == "x"} {
					file attributes $tmplocalpath -permissions +x
				}

				file rename -force -- $tmplocalpath $localpath
			}
			catch {
				file delete -force -- $tmplocalpath
			}

			return $localpath
		}

		return $localcachefile
	}
}