func RewriteAsStub(rep repo.RepositoryWriter) RewriteFailedEntryCallback {
	return func(ctx context.Context, parentPath string, input *snapshot.DirEntry, originalErr error) (*snapshot.DirEntry, error) {
		var buf bytes.Buffer

		e := json.NewEncoder(&buf)
		e.SetIndent("  ", "    ")

		if err := e.Encode(UnreadableDirEntryReplacement{
			"Kopia replaced the original entry with this stub because of an error.",
			originalErr.Error(),
			input,
		}); err != nil {
			return nil, errors.Wrap(err, "error writing stub contents")
		}

		w := rep.NewObjectWriter(ctx, object.WriterOptions{})

		n, err := buf.WriteTo(w)
		if err != nil {
			return nil, errors.Wrap(err, "error writing stub")
		}

		oid, err := w.Result()
		if err != nil {
			return nil, errors.Wrap(err, "error writing stub")
		}

		return &snapshot.DirEntry{
			Name:        ".INVALID." + input.Name,
			Type:        snapshot.EntryTypeFile,
			ModTime:     input.ModTime,
			FileSize:    n,
			UserID:      input.UserID,
			GroupID:     input.GroupID,
			ObjectID:    oid,
			Permissions: input.Permissions,
		}, nil
	}
}
// RewriteAsStub returns a callback that replaces the invalid entry with a stub that describes
// the error.
RewriteAsStub returns a callback that replaces the invalid entry with a stub that describes
the error.
// RewriteAsStub returns a callback that replaces the invalid entry with a stub that describes // the error .
func RewriteAsStub(rep repo.RepositoryWriter) RewriteFailedEntryCallback {
	return func(ctx context.Context, parentPath string, input *snapshot.DirEntry, originalErr error) (*snapshot.DirEntry, error) {
		var buf bytes.Buffer
		e := json.NewEncoder(&buf)
		e.SetIndent("  ", "    ")
		if err := e.Encode(UnreadableDirEntryReplacement{
			"Kopia replaced the original entry with this stub because of an error.",
			originalErr.Error(),
			input,
		}); err != nil {
			return nil, errors.Wrap(err, "error writing stub contents")
		}
		w := rep.NewObjectWriter(ctx, object.WriterOptions{})
		n, err := buf.WriteTo(w)
		if err != nil {
			return nil, errors.Wrap(err, "error writing stub")
		}
		oid, err := w.Result()
		if err != nil {
			return nil, errors.Wrap(err, "error writing stub")
		}
		return &snapshot.DirEntry{
			Name:        ".INVALID." + input.Name,
			Type:        snapshot.EntryTypeFile,
			ModTime:     input.ModTime,
			FileSize:    n,
			UserID:      input.UserID,
			GroupID:     input.GroupID,
			ObjectID:    oid,
			Permissions: input.Permissions,
		}, nil
	}
}
func RewriteAsStub ( rep repo . RepositoryWriter ) RewriteFailedEntryCallback { return func ( ctx context . Context , parentPath string , input * snapshot . DirEntry , originalErr error ) ( * snapshot . DirEntry , error ) { var buf bytes . Buffer e := json . NewEncoder ( & buf ) e . SetIndent ( " " , " " ) if err := e . Encode ( UnreadableDirEntryReplacement { " " , originalErr . Error ( ) , input , } ) ; err != nil { return nil , errors . Wrap ( err , " " ) } w := rep . NewObjectWriter ( ctx , object . WriterOptions { } ) n , err := buf . WriteTo ( w ) if err != nil { return nil , errors . Wrap ( err , " " ) } oid , err := w . Result ( ) if err != nil { return nil , errors . Wrap ( err , " " ) } return & snapshot . DirEntry { Name : " " + input . Name , Type : snapshot . EntryTypeFile , ModTime : input . ModTime , FileSize : n , UserID : input . UserID , GroupID : input . GroupID , ObjectID : oid , Permissions : input . Permissions , } , nil } }
RewriteAsStub returns a callback that replaces the invalid entry with a stub that describes
the error.
RewriteAsStub returns a callback that replaces the invalid entry with a stub that describes the error .