457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
if {[info exists pathinfo(package)] && [info exists pathinfo(hostname)] && [info exists pathinfo(file)]} {
set dir [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
foreach file [glob -nocomplain -tails -directory $dir -types {d f l} {{.,}*}] {
if {$file == "." || $file == ".."} {
continue
}
if {[lsearch -exact $retval $file] != -1} {
continue
}
lappend retval $file
}
|
>
>
>
>
>
>
>
>
>
|
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
if {[info exists pathinfo(package)] && [info exists pathinfo(hostname)] && [info exists pathinfo(file)]} {
set dir [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
foreach file [glob -nocomplain -tails -directory $dir -types {d f l} {{.,}*}] {
if {$file == "." || $file == ".."} {
continue
}
if {[string match "*.APPFS.WHITEOUT" $file]} {
set remove [string range $file 0 end-15]
set idx [lsearch -exact $retval $remove]
if {$idx != -1} {
set retval [lreplace $retval $idx $idx]
}
continue
}
if {[lsearch -exact $retval $file] != -1} {
continue
}
lappend retval $file
}
|
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
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)]
set retval(localpath) $localpath
if {[file exists $localpath]} {
catch {
file lstat $localpath localpathinfo
set retval(time) $localpathinfo(mtime)
switch -- $localpathinfo(type) {
"directory" {
set retval(type) "directory"
set retval(childcount) 2
}
"file" {
set retval(type) "file"
set retval(size) $localpathinfo(size)
if {[file executable $localpath]} {
set retval(perms) "x"
} else {
set retval(perms) ""
}
}
"link" {
set retval(type) "symlink"
set retval(source) [file readlink $localpath]
}
}
} err
} else {
set work [split $pathinfo(file) "/"]
set directory [join [lrange $work 0 end-1] "/"]
set file [lindex $work end]
::appfs::db eval {SELECT type, time, source, size, perms FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_directory = $directory AND file_name = $file;} retval {}
unset -nocomplain retval(*)
}
}
}
if {![info exists retval(type)]} {
return -code error "No such file or directory"
|
<
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
|
|
|
|
>
|
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
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)]
set retval(localpath) $localpath
if {![file exists "${localpath}.APPFS.WHITEOUT"]} {
if {[file exists $localpath]} {
set retval(is_localfile) 1
catch {
file lstat $localpath localpathinfo
set retval(time) $localpathinfo(mtime)
switch -- $localpathinfo(type) {
"directory" {
set retval(type) "directory"
set retval(childcount) 2
}
"file" {
set retval(type) "file"
set retval(size) $localpathinfo(size)
if {[file executable $localpath]} {
set retval(perms) "x"
} else {
set retval(perms) ""
}
}
"link" {
set retval(type) "symlink"
set retval(source) [file readlink $localpath]
}
}
} err
} else {
set retval(is_remotefile) 1
set work [split $pathinfo(file) "/"]
set directory [join [lrange $work 0 end-1] "/"]
set file [lindex $work end]
::appfs::db eval {SELECT type, time, source, size, perms FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_directory = $directory AND file_name = $file;} retval {}
unset -nocomplain retval(*)
}
}
}
}
if {![info exists retval(type)]} {
return -code error "No such file or directory"
|
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
if {$pathinfo(_type) != "files"} {
return -code error "invalid type"
}
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 {}
|
>
>
|
|
|
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
if {$pathinfo(_type) != "files"} {
return -code error "invalid type"
}
set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
if {$mode == "create"} {
file delete -- "${localpath}.APPFS.WHITEOUT"
return $localpath
}
if {[file exists $localpath]} {
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 {}
|
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
|
set dirname [file dirname $filename]
file mkdir $dirname
return $filename
}
proc prepare_to_create {path} {
if {[exists $path] != ""} {
return -code error "File already exists"
}
set filename [openpath $path "create"]
set dirname [file dirname $filename]
file mkdir $dirname
return $filename
}
proc localpath {path} {
array set pathinfo [_parsepath $path]
if {$pathinfo(_type) != "files"} {
return -code error "invalid type"
}
set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
return $localpath
}
}
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
|
set dirname [file dirname $filename]
file mkdir $dirname
return $filename
}
proc localpath {path} {
array set pathinfo [_parsepath $path]
if {$pathinfo(_type) != "files"} {
return -code error "invalid type"
}
set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
return $localpath
}
proc _delete_files_except_whiteout {path} {
foreach file [glob -nocomplain -directory $path {{.,}*}] {
if {[string match "*/.." $file] || [string match "*/." $file]} {
continue
}
if {[file isdirectory $file]} {
_delete_files_except_whiteout $file
}
if {[string match "*.APPFS.WHITEOUT" $file]} {
continue
}
catch {
file delete -- $file
}
}
}
proc unlinkpath {path} {
array set pathattrs [exists $path]
if {![info exists pathattrs(packaged)]} {
return -code error "invalid type"
}
set localpath $pathattrs(localpath)
set whiteout 0
set isdirectory 0
if {[info exists pathattrs(is_localfile)]} {
if {[file isdirectory $localpath]} {
set isdirectory 1
set whiteout 1
_delete_files_except_whiteout $localpath
} else {
file delete -force -- $localpath
}
} elseif {[info exists pathattrs(is_remotefile)]} {
if {$pathattrs(type) == "directory"} {
set isdirectory 1
}
set whiteout 1
} else {
return -code error "Unknown if file is remote or local !?"
}
if {$isdirectory} {
set children [getchildren $path]
if {$children != [list]} {
return -code error "Asked to delete non-empty directory"
}
}
if {$whiteout} {
set whiteoutfile "${localpath}.APPFS.WHITEOUT"
set whiteoutdir [file dirname $whiteoutfile]
file mkdir $whiteoutdir
close [open $whiteoutfile w]
}
}
}
|