// Ensure that f.content != nil // // LOCKS_REQUIRED(f.mu) func (f *FileInode) ensureContent(ctx context.Context) (err error) { // Is there anything to do? if f.content != nil { return } // Open a reader for the generation we care about. rc, err := f.bucket.NewReader( ctx, &gcs.ReadObjectRequest{ Name: f.src.Name, Generation: f.src.Generation, }) if err != nil { err = fmt.Errorf("NewReader: %v", err) return } defer rc.Close() // Create a temporary file with its contents. tf, err := gcsx.NewTempFile(rc, f.tempDir, f.mtimeClock) if err != nil { err = fmt.Errorf("NewTempFile: %v", err) return } // Update state. f.content = tf return }
func (t *TempFileTest) SetUp(ti *TestInfo) { var err error t.ctx = ti.Ctx // Set up the clock. t.clock.SetTime(time.Date(2012, 8, 15, 22, 56, 0, 0, time.Local)) // And the temp file. t.tf.wrapped, err = gcsx.NewTempFile( strings.NewReader(initialContent), "", &t.clock) AssertEq(nil, err) }
func (t *IntegrationTest) create(o *gcs.Object) { // Set up a reader. rc, err := t.bucket.NewReader( t.ctx, &gcs.ReadObjectRequest{ Name: o.Name, Generation: o.Generation, }) AssertEq(nil, err) // Use it to create the temp file. t.tf, err = gcsx.NewTempFile(rc, "", &t.clock) AssertEq(nil, err) // Close it. err = rc.Close() AssertEq(nil, err) }