| 980 | } |
| 981 | |
| 982 | int |
| 983 | LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConflicts) |
| 984 | { |
| 985 | int retVal = NO_FILENAME_CONFLICTS; |
| 986 | |
| 987 | const char *filename = log_object->get_full_filename(); |
| 988 | |
| 989 | if (access(filename, F_OK)) { |
| 990 | if (errno != ENOENT) { |
| 991 | const char *msg = "Cannot access log file %s: %s"; |
| 992 | const char *se = strerror(errno); |
| 993 | |
| 994 | Error(msg, filename, se); |
| 995 | retVal = ERROR_ACCESSING_LOG_FILE; |
| 996 | } |
| 997 | } else { |
| 998 | // file exists, try to read metafile to get object signature |
| 999 | // |
| 1000 | uint64_t signature = 0; |
| 1001 | BaseMetaInfo meta_info(filename); |
| 1002 | bool conflicts = true; |
| 1003 | |
| 1004 | if (meta_info.file_open_successful()) { |
| 1005 | bool got_sig = meta_info.get_log_object_signature(&signature); |
| 1006 | uint64_t obj_sig = log_object->get_signature(); |
| 1007 | |
| 1008 | if (got_sig && signature == obj_sig) { |
| 1009 | conflicts = false; |
| 1010 | } |
| 1011 | Dbg(dbg_ctl_log, |
| 1012 | "LogObjectManager::_solve_filename_conflicts\n" |
| 1013 | "\tfilename = %s\n" |
| 1014 | "\tmeta file signature = %" PRIu64 "\n" |
| 1015 | "\tlog object signature = %" PRIu64 "\n" |
| 1016 | "\tconflicts = %d", |
| 1017 | filename, signature, obj_sig, conflicts); |
| 1018 | } |
| 1019 | |
| 1020 | if (conflicts) { |
| 1021 | if (maxConflicts == 0) { |
| 1022 | // do not take any action, and return an error status |
| 1023 | // |
| 1024 | const char *msg = "Cannot solve filename conflicts for log file %s"; |
| 1025 | |
| 1026 | Error(msg, filename); |
| 1027 | retVal = CANNOT_SOLVE_FILENAME_CONFLICTS; |
| 1028 | } else { |
| 1029 | // Either the meta file could not be read, or the new object's |
| 1030 | // signature and the metafile signature do not match. |
| 1031 | // Roll the old filename so the new object can use the filename |
| 1032 | // it requested (previously we used to rename the NEW file |
| 1033 | // but now we roll the OLD file). However, if the log object writes to |
| 1034 | // a pipe don't roll because rolling is not applicable to pipes. |
| 1035 | |
| 1036 | bool roll_file = true; |
| 1037 | |
| 1038 | if (log_object->writes_to_pipe()) { |
| 1039 | // Verify whether the existing file is a pipe. If it is, |
nothing calls this directly
no test coverage detected