vikramahuja1001 commented on a change in pull request #3917: URL: https://github.com/apache/carbondata/pull/3917#discussion_r516851234
########## File path: core/src/main/java/org/apache/carbondata/core/util/path/TrashUtil.java ########## @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.carbondata.core.util.path; + +import java.io.File; +import java.io.IOException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +import org.apache.carbondata.common.logging.LogServiceFactory; +import org.apache.carbondata.core.constants.CarbonCommonConstants; +import org.apache.carbondata.core.datastore.filesystem.CarbonFile; +import org.apache.carbondata.core.datastore.impl.FileFactory; +import org.apache.carbondata.core.exception.CarbonFileException; +import org.apache.carbondata.core.util.CarbonUtil; + +import org.apache.commons.io.FileUtils; + +import org.apache.log4j.Logger; + +/** + * Mantains the trash folder in carbondata. This class has methods to copy data to the trash and + * remove data from the trash. + */ +public final class TrashUtil { + + private static final Logger LOGGER = + LogServiceFactory.getLogService(CarbonUtil.class.getName()); + + /** + * The below method copies the complete a file to the trash folder. Provide necessary + * timestamp and the segment number in the suffixToAdd variable, so that the proper folder is + * created in the trash folder. + * + * @param carbonTablePath table path of the carbon table + * @param pathOfFileToCopy the files which are to be moved to the trash folder + * @param suffixToAdd timestamp, partition folder(if any) and segment number + * @return + */ + public static void copyDataToTrashFolderByFile(String carbonTablePath, String pathOfFileToCopy, + String suffixToAdd) { + String trashFolderPath = CarbonTablePath.getTrashFolderPath(carbonTablePath) + + CarbonCommonConstants.FILE_SEPARATOR + suffixToAdd; + try { + if (new File(pathOfFileToCopy).exists()) { + FileUtils.copyFileToDirectory(new File(pathOfFileToCopy), new File(trashFolderPath)); + LOGGER.info("File: " + pathOfFileToCopy + " successfully copied to the trash folder: " + + trashFolderPath); + } + } catch (IOException e) { + LOGGER.error("Unable to copy " + pathOfFileToCopy + " to the trash folder", e); + } + } + + /** + * The below method copies the complete segment folder to the trash folder. Provide necessary + * timestamp and the segment number in the suffixToAdd variable, so that the proper folder is + * created in the trash folder. + * + * @param carbonTablePath table path of the carbon table + * @param path the folder which are to be moved to the trash folder + * @param suffixToAdd timestamp, partition folder(if any) and segment number + * @return + */ + public static void copyDataToTrashBySegment(CarbonFile path, String carbonTablePath, + String suffixToAdd) { + String trashFolderPath = CarbonTablePath.getTrashFolderPath(carbonTablePath) + + CarbonCommonConstants.FILE_SEPARATOR + suffixToAdd; + try { + FileUtils.copyDirectory(new File(path.getAbsolutePath()), new File(trashFolderPath)); Review comment: in this case while copying directory, should i list the files then move them one by one or is there any other way to copy directory using FileFactory.getDataOutputStream, FileFactory.getDataInputStream, IOUtils.copyBytes ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org