| 123 | public: |
| 124 | using OpKernel::OpKernel; |
| 125 | void Compute(OpKernelContext* context) override { |
| 126 | const Tensor* filename_input; |
| 127 | const Tensor* contents_input; |
| 128 | OP_REQUIRES_OK(context, context->input("filename", &filename_input)); |
| 129 | OP_REQUIRES_OK(context, context->input("contents", &contents_input)); |
| 130 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(filename_input->shape()), |
| 131 | errors::InvalidArgument( |
| 132 | "Input filename tensor must be scalar, but had shape: ", |
| 133 | filename_input->shape().DebugString())); |
| 134 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(contents_input->shape()), |
| 135 | errors::InvalidArgument( |
| 136 | "Contents tensor must be scalar, but had shape: ", |
| 137 | contents_input->shape().DebugString())); |
| 138 | const string& filename = filename_input->scalar<tstring>()(); |
| 139 | const string dir(io::Dirname(filename)); |
| 140 | if (!context->env()->FileExists(dir).ok()) { |
| 141 | OP_REQUIRES_OK(context, context->env()->RecursivelyCreateDir(dir)); |
| 142 | } |
| 143 | OP_REQUIRES_OK(context, |
| 144 | WriteStringToFile(context->env(), filename, |
| 145 | contents_input->scalar<tstring>()())); |
| 146 | } |
| 147 | }; |
| 148 | |
| 149 | REGISTER_KERNEL_BUILDER(Name("WriteFile").Device(DEVICE_CPU), WriteFileOp); |
nothing calls this directly
no test coverage detected