Skip to content

Commit

Permalink
FileUtil#setExecutable
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMirzayanov committed May 14, 2024
1 parent 65d3c65 commit 6cfbd59
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions code/src/main/java/com/codeforces/commons/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import de.schlichtherle.truezip.file.TFileInputStream;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.Contract;

import javax.annotation.Nonnegative;
Expand All @@ -33,6 +34,8 @@
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class FileUtil {
private static final Logger logger = Logger.getLogger(FileUtil.class);

public static final long TB_PER_PB = 1024L;

public static final long GB_PER_TB = 1024L;
Expand Down Expand Up @@ -1043,6 +1046,27 @@ private static long parseSize(@Nonnull String size, @Nonnegative int lastCharInd
return NumberUtil.toLong(Double.parseDouble(size.substring(0, lastCharIndex).trim()) * unit);
}

/**
* Set executable permission for file.
*
* @param file File to set permission.
* @param executable {@code true} to set executable permission.
*/
public static void setExecutable(@Nonnull File file, boolean executable) {
if (!file.setExecutable(executable)) {
logger.warn("Can't set executable permission for file '" + file + "' [executable=" + executable + "].");
}
}

/**
* Set executable permission for file.
*
* @param file File to set permission.
*/
public static void setExecutable(@Nonnull File file) {
setExecutable(file, true);
}

/**
* Excludes service files, such as hidden or svn.
*/
Expand Down

0 comments on commit 6cfbd59

Please sign in to comment.