MCPcopy Create free account
hub / github.com/apache/pig / validateLogFile

Method validateLogFile

src/org/apache/pig/Main.java:992–1080  ·  view source on GitHub ↗
(String logFileName, File scriptFile)

Source from the content-addressed store, hash-verified

990 }
991
992 private static String validateLogFile(String logFileName, File scriptFile) {
993 String strippedDownScriptName = null;
994
995 if (scriptFile != null) {
996 if(!scriptFile.isDirectory()) {
997 String scriptFileAbsPath;
998 try {
999 scriptFileAbsPath = scriptFile.getCanonicalPath();
1000 strippedDownScriptName = getFileFromCanonicalPath(scriptFileAbsPath);
1001 } catch (IOException ioe) {
1002 log.warn("Could not compute canonical path to the script file " + ioe.getMessage());
1003 strippedDownScriptName = null;
1004 }
1005 }
1006 }
1007
1008 String defaultLogFileName = (strippedDownScriptName == null ? "pig_" : strippedDownScriptName) + new Date().getTime() + ".log";
1009 File logFile;
1010
1011 if(logFileName != null) {
1012 logFile = new File(logFileName);
1013
1014 //Check if the file name is a directory
1015 //append the default file name to the file
1016 if(logFile.isDirectory()) {
1017 if(logFile.canWrite()) {
1018 try {
1019 logFileName = logFile.getCanonicalPath() + File.separator + defaultLogFileName;
1020 } catch (IOException ioe) {
1021 log.warn("Could not compute canonical path to the log file " + ioe.getMessage());
1022 return null;
1023 }
1024 return logFileName;
1025 } else {
1026 log.warn("Need write permission in the directory: " + logFileName + " to create log file.");
1027 return null;
1028 }
1029 } else {
1030 //we have a relative path or an absolute path to the log file
1031 //check if we can write to the directory where this file is/will be stored
1032
1033 if (logFile.exists()) {
1034 if(logFile.canWrite()) {
1035 try {
1036 logFileName = new File(logFileName).getCanonicalPath();
1037 } catch (IOException ioe) {
1038 log.warn("Could not compute canonical path to the log file " + ioe.getMessage());
1039 return null;
1040 }
1041 return logFileName;
1042 } else {
1043 //do not have write permissions for the log file
1044 //bail out with an error message
1045 log.warn("Cannot write to file: " + logFileName + ". Need write permission.");
1046 return logFileName;
1047 }
1048 } else {
1049 logFile = logFile.getParentFile();

Callers 1

runMethod · 0.95

Calls 6

getPropertyMethod · 0.80
warnMethod · 0.65
existsMethod · 0.65
isDirectoryMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected