func saveTenantID(path string, tenantID string) error {
	var perm os.FileMode = 0600

	dir := filepath.Dir(path)
	if err := os.MkdirAll(dir, os.ModePerm); err != nil {
		return fmt.Errorf("Failed to create directory %s: %v", dir, err)
	}

	f, err := ioutil.TempFile(dir, "tenantid")
	if err != nil {
		return fmt.Errorf("Failed to create temp file: %v", err)
	}
	defer f.Close()

	fp := f.Name()
	if _, err := f.Write([]byte(tenantID)); err != nil {
		return fmt.Errorf("Failed to write tenant ID to file: %v", err)
	}
	f.Close()

	// atomic move by rename
	if err := os.Rename(fp, path); err != nil {
		return fmt.Errorf("Failed to rename file. src=%s dst=%s error=%v", fp, path, err)
	}
	if err := os.Chmod(path, perm); err != nil {
		return fmt.Errorf("Failed to chmod the file %s: %v", path, err)
	}
	return nil
}
func saveTenantID(path string, tenantID string) error {
	var perm os.FileMode = 0600

	dir := filepath.Dir(path)
	if err := os.MkdirAll(dir, os.ModePerm); err != nil {
		return fmt.Errorf("Failed to create directory %s: %v", dir, err)
	}

	f, err := ioutil.TempFile(dir, "tenantid")
	if err != nil {
		return fmt.Errorf("Failed to create temp file: %v", err)
	}
	defer f.Close()

	fp := f.Name()
	if _, err := f.Write([]byte(tenantID)); err != nil {
		return fmt.Errorf("Failed to write tenant ID to file: %v", err)
	}
	f.Close()

	
	if err := os.Rename(fp, path); err != nil {
		return fmt.Errorf("Failed to rename file. src=%s dst=%s error=%v", fp, path, err)
	}
	if err := os.Chmod(path, perm); err != nil {
		return fmt.Errorf("Failed to chmod the file %s: %v", path, err)
	}
	return nil
}
func saveTenantID ( path string , tenantID string ) error { var perm os . FileMode = 0600 dir := filepath . Dir ( path ) if err := os . MkdirAll ( dir , os . ModePerm ) ; err != nil { return fmt . Errorf ( " " , dir , err ) } f , err := ioutil . TempFile ( dir , " " ) if err != nil { return fmt . Errorf ( " " , err ) } defer f . Close ( ) fp := f . Name ( ) if _ , err := f . Write ( [ ] byte ( tenantID ) ) ; err != nil { return fmt . Errorf ( " " , err ) } f . Close ( ) // atomic move by rename if err := os . Rename ( fp , path ) ; err != nil { return fmt . Errorf ( " " , fp , path , err ) } if err := os . Chmod ( path , perm ) ; err != nil { return fmt . Errorf ( " " , path , err ) } return nil }
// saveTenantID performs an atomic write to the path with given tenantID contents.
saveTenantID performs an atomic write to the path with given tenantID contents .