Check-in [d836b9fc43]
Overview
Comment:Added more reliable write support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tcl-ops
Files: files | file ages | folders
SHA1: d836b9fc4376f3a3e5cf4054f2a4866f147734f5
User & Date: rkeene on 2014-11-07 13:19:35
Other Links: branch diff | manifest | tags
Context
2014-11-08
19:33
Removed SQLite dependency check-in: d74c945fc0 user: rkeene tags: tcl-ops
2014-11-07
13:19
Added more reliable write support check-in: d836b9fc43 user: rkeene tags: tcl-ops
13:04
Added validity checking for various types check-in: 5685a8f9a8 user: rkeene tags: tcl-ops
Changes

Modified appfsd.c from [5b32138d43] to [c5ca9c2598].

639
640
641
642
643
644
645




646
647
648
649
650
651
652
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656







+
+
+
+







	} else {
		/* The file must already exist */
		if (gpi_ret != 0) {
			return(gpi_ret);
		}

		mode = "";

		if ((fi->flags & O_WRONLY) == O_WRONLY) {
			mode = "write";
		}
	}

	if (pathinfo.type == APPFS_PATHTYPE_DIRECTORY) {
		return(-EISDIR);
	}

	interp = appfs_TclInterp();

Modified appfsd.tcl from [25e6dbc0f2] to [6f6d010e1e].

476
477
478
479
480
481
482





483
484
485
486
487
488
489
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494







+
+
+
+
+








		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" {
522
523
524
525
526
527
528

529
530
531
532
533
534
535
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541







+







					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)
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
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







+
+
+
+




-
+

-
+



-
+

-
+

+
+
-
-
+
+
+
+
+
+
+
+
+
+
+







		}

		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]
		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;}]
		::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 {$file_sha1 == ""} {
		if {$pkgpathinfo(file_sha1) == ""} {
			return -code error "No such file or directory"
		}

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

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

			catch {
			file copy -force -- $localcachefile $tmplocalpath
			file rename -force -- $tmplocalpath $localpath
				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
	}
}