reworking
This commit is contained in:
@@ -1,10 +1,40 @@
|
||||
/* is HERE this out-for-edit by the owner ??? */
|
||||
|
||||
/*
|
||||
|
||||
TODO
|
||||
change to execute permissions on apRemoveScript
|
||||
|
||||
TODO - if the apRemoveScript is empty - skip the postamble
|
||||
TODO - change the whole tool
|
||||
|
||||
from the shadow point of view
|
||||
dirwalk from ../. (shadow directory)
|
||||
|
||||
if regular file - do
|
||||
if SCCS file and out for edit
|
||||
(report as EDIT)
|
||||
else if SCCS file and Not out for edit
|
||||
1. (report as illegal file - should be a link)
|
||||
2. place on the remove list
|
||||
else
|
||||
1. place on the remove list
|
||||
if link - do
|
||||
if a relative link (starts with ../ or ./ )
|
||||
should agree with the appl system area (relative)
|
||||
else if it doesn't terminate (no access)
|
||||
1. (report as link component failure)
|
||||
2. place on the remove list
|
||||
else if it terminates in the wrong place
|
||||
1. (report as illegal link)
|
||||
2. place on the remove list
|
||||
|
||||
if dir - do
|
||||
if name == SCCS
|
||||
1. (report as illegal SCCS directory)
|
||||
2. place on the remove list
|
||||
else if NOT in the system area
|
||||
1. place on the remove list
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
* APSTATUSSYNC.C
|
||||
@@ -20,6 +50,7 @@ TODO - if the apRemoveScript is empty - skip the postamble
|
||||
* dest. is not in the application system area or EPICS
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -31,7 +62,7 @@ TODO - if the apRemoveScript is empty - skip the postamble
|
||||
void procDirEntries();
|
||||
int processFile();
|
||||
int getAppSysPath();
|
||||
int checkLink();
|
||||
int procLinkEntries();
|
||||
int dirwalk();
|
||||
int verbose;
|
||||
extern int errno;
|
||||
@@ -64,8 +95,8 @@ main(argc, argv)
|
||||
verbose = TRUE;
|
||||
else
|
||||
verbose = FALSE;
|
||||
|
||||
fprintf(stdout, "\n\napStatusSync: Status Started ==>> ==>> ==>> ==>> ==>>\n");
|
||||
fprintf(stdout, "===========================================================\n");
|
||||
if ((initScriptFile()) != 0)
|
||||
return (-1);
|
||||
if ((processTopDir()) != 0)
|
||||
@@ -89,6 +120,7 @@ getAppSysPath()
|
||||
char *epics_path_file = "current_rel";
|
||||
char app_path[MAXPATHLEN];
|
||||
char epics_path[MAXPATHLEN];
|
||||
resolved_path[0] = '\0';
|
||||
if ((fp = fopen(app_path_file, "r")) == NULL) {
|
||||
fprintf(stdout, "apStatusSync: can't fopen %s\n", app_path_file);
|
||||
fprintf(stdout, "Probably not at root of application shadow node\n");
|
||||
@@ -105,7 +137,7 @@ getAppSysPath()
|
||||
}
|
||||
/* reset App SYS to real path if not on server */
|
||||
if ((pt = (void *) realpath(app_path, resolved_path)) == NULL) {
|
||||
fprintf(stdout, "FATAL ERROR - failed link component of %s=%s\n",
|
||||
fprintf(stdout, "\tFATAL ERROR - failed link component of %s=%s\n",
|
||||
app_path, resolved_path);
|
||||
return (-1);
|
||||
}
|
||||
@@ -128,7 +160,7 @@ getAppSysPath()
|
||||
}
|
||||
/* reset epics path to real path if not on server */
|
||||
if ((pt = (void *) realpath(epics_path, resolved_path)) == NULL) {
|
||||
fprintf(stdout, "FATAL ERROR - failed link component of %s=%s\n",
|
||||
fprintf(stdout, "\tFATAL ERROR - failed link component of %s=%s\n",
|
||||
epics_path, resolved_path);
|
||||
return (-1);
|
||||
}
|
||||
@@ -137,8 +169,6 @@ getAppSysPath()
|
||||
strcpy(pEpicsRelease, pt);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
PROCESSFILE
|
||||
for each regular file:
|
||||
@@ -148,10 +178,9 @@ PROCESSFILE
|
||||
print dir file and contents of p.dot
|
||||
****************************************************************************/
|
||||
int
|
||||
processFile(name, dir, pfirstTime)
|
||||
processFile(name, dir)
|
||||
char *name; /* regular file */
|
||||
char *dir; /* current directory */
|
||||
int *pfirstTime;
|
||||
{
|
||||
char sccsDir[MAXNAMLEN];
|
||||
char sdotName[MAXNAMLEN];
|
||||
@@ -160,6 +189,9 @@ processFile(name, dir, pfirstTime)
|
||||
char *pbeg; /* beg of file pathname */
|
||||
char *pend; /* beg of filename */
|
||||
char *pendm1; /* beg of filename */
|
||||
char *plogname; /* logname pointer */
|
||||
char *pUserDotName; /* end of out-for-EDIT p.dot line */
|
||||
char udotname[80]; /* took file out-for-edit user name */
|
||||
struct stat stbuf;
|
||||
struct stat lstbuf;
|
||||
FILE *fp;
|
||||
@@ -185,6 +217,7 @@ processFile(name, dir, pfirstTime)
|
||||
pendm1 = pend;
|
||||
pendm1--;
|
||||
/* pend points to filename */
|
||||
|
||||
/* skip some setup files */
|
||||
if ((strstr(pendm1, ".applShadow")) != NULL)
|
||||
return;
|
||||
@@ -198,9 +231,9 @@ processFile(name, dir, pfirstTime)
|
||||
|
||||
if (lstat(sccsDir, &lstbuf) == -1) {
|
||||
hasSccsDir = FALSE;
|
||||
} else
|
||||
} else {
|
||||
hasSccsDir = TRUE;
|
||||
|
||||
}
|
||||
/* form p.dot name */
|
||||
strcpy(pdotName, dir);
|
||||
strcat(pdotName, "/");
|
||||
@@ -220,18 +253,36 @@ processFile(name, dir, pfirstTime)
|
||||
fprintf(stdout, "processFile: can't fopen %s\n", pdotName);
|
||||
return (-1);
|
||||
}
|
||||
if ((plogname = getenv("LOGNAME")) == 0) {
|
||||
fprintf(stdout, "apStatusSync: Can't get LOGNAME\n");
|
||||
return (-1);
|
||||
}
|
||||
if ((fgets(ibuf, MAXPATHLEN, fp)) != NULL) {
|
||||
/* is this the original sccs out-for-edit owner ??? */
|
||||
strcpy(udotname, ibuf);
|
||||
pUserDotName = strstr(udotname, plogname);
|
||||
strtok(pUserDotName, " ");
|
||||
if ((strcmp(pUserDotName, plogname)) != 0) {
|
||||
/* yes - skip */
|
||||
return (0);
|
||||
}
|
||||
/* else print status */
|
||||
fprintf(stdout, "%-20s %-25s EDIT - %s", dir, pend, ibuf);
|
||||
} else
|
||||
fprintf(stdout, "FATAL ERROR - reading %s%s\n", pdot, pend);
|
||||
} else {
|
||||
fprintf(stdout, "\tFATAL ERROR - reading %s%s\n", pdot, pend);
|
||||
}
|
||||
fclose(fp);
|
||||
} else if (hasPdot && !hasSdot) {
|
||||
/* stray ??? regular files in directories */
|
||||
/* stray ??? somebody removed the s.dot */
|
||||
fprintf(stdout, "Warning - someone removed '%s' from sccs control\nw/o removing the lock file\n", name);
|
||||
sprintf(buffer, "#/bin/rm -f ./%s\n", name);
|
||||
if ((appendToScriptFile(buffer)) < 0)
|
||||
return (-1); /* should not happen */
|
||||
} else if (!hasPdot && hasSdot) {
|
||||
fprintf(stdout, "FATAL ERROR - file %s should be a link\n", name);
|
||||
fprintf(stdout, "\tFATAL ERROR - file %s should be a link\n", name);
|
||||
sprintf(buffer, "#/bin/rm -f ./%s\n", name);
|
||||
if ((appendToScriptFile(buffer)) < 0)
|
||||
return (-1);
|
||||
} else if (!hasPdot && !hasSdot) {
|
||||
/* stray ??? regular files in directories */
|
||||
sprintf(buffer, "#/bin/rm -f ./%s\n", name);
|
||||
@@ -250,18 +301,17 @@ procDirEntries(name, dir)
|
||||
char *dir; /* current directory */
|
||||
{
|
||||
struct stat stbuf;
|
||||
int firstTime;
|
||||
if (lstat(name, &stbuf) == -1) {
|
||||
fprintf(stdout, "procDirEntries: can't access %s\n", name);
|
||||
return;
|
||||
}
|
||||
if ((stbuf.st_mode & S_IFMT) == S_IFLNK) {
|
||||
checkLink(name);
|
||||
procLinkEntries(name);
|
||||
return;
|
||||
}
|
||||
if ((stbuf.st_mode & S_IFMT) == S_IFREG) {
|
||||
firstTime = TRUE;
|
||||
processFile(name, dir, &firstTime);
|
||||
processFile(name, dir);
|
||||
/* DEBUG DONE */
|
||||
return;
|
||||
}
|
||||
if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
|
||||
@@ -269,18 +319,26 @@ procDirEntries(name, dir)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
CHECKLINK
|
||||
PROCLINKENTRIES
|
||||
checks valid symbolic link for EPICS
|
||||
at entry path is the name of a local link
|
||||
****************************************************************************/
|
||||
int
|
||||
checkLink(path)
|
||||
procLinkEntries(path)
|
||||
char *path;
|
||||
{
|
||||
char resolved_path[MAXPATHLEN];
|
||||
char buf[MAXPATHLEN];
|
||||
char buf2[MAXPATHLEN];
|
||||
char buf3[MAXPATHLEN];
|
||||
char buffer[MAXNAMLEN];
|
||||
void *pt;
|
||||
int nchars;
|
||||
resolved_path[0] = '\0';
|
||||
if ((pt = (void *) realpath(path, resolved_path)) == NULL) {
|
||||
fprintf(stdout, "FATAL ERROR - failed link component of %s=%s\n",
|
||||
fprintf(stdout, "\tFATAL ERROR - failed link component of %s=%s\n",
|
||||
path, resolved_path);
|
||||
return;
|
||||
}
|
||||
@@ -290,6 +348,38 @@ checkLink(path)
|
||||
/* skip any link path with "/vw/" in it */
|
||||
if ((strstr(resolved_path, "/vw/")) != NULL)
|
||||
return;
|
||||
|
||||
/* assume a relative link name doesn't begin with a '/' character */
|
||||
buf[0] = '\0';
|
||||
if ((nchars = readlink(path, buf, MAXPATHLEN)) < 0) {
|
||||
fprintf(stdout, "\treadlink failed errno=%d\n", errno);
|
||||
sprintf(buffer, "#/bin/rm -f ./%s\n", path);
|
||||
if ((appendToScriptFile(buffer)) < 0)
|
||||
return ;
|
||||
}
|
||||
buf[nchars] = '\0';
|
||||
if (buf[0] != '/') {
|
||||
/*ensure that the equivalent link exists in the system area */
|
||||
strcpy(buf2, pAppSysTop);
|
||||
strcat(buf2, "/");
|
||||
strcat(buf2, path);
|
||||
buf3[0] = '\0';
|
||||
if ((nchars = readlink(buf2, buf3, MAXPATHLEN)) < 0) {
|
||||
fprintf(stdout,
|
||||
"\treadlink failed - local link '%s' sys link '%s'\n" ,path, buf2);
|
||||
sprintf(buffer, "#/bin/rm -f ./%s\n", path);
|
||||
if ((appendToScriptFile(buffer)) < 0)
|
||||
return (-1);
|
||||
}
|
||||
buf3[nchars] = '\0';
|
||||
if ((strcmp(buf3, buf)) != 0) {
|
||||
fprintf(stdout, "\tA wrong relative link was detected\n");
|
||||
fprintf(stdout, "\t\tsrc '%s' dest '%s'\n", path, buf3);
|
||||
sprintf(buffer, "#/bin/rm -f ./%s\n", path);
|
||||
if ((appendToScriptFile(buffer)) < 0)
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
/* compare $epics or app SYS or beg of shadow with beg of dest */
|
||||
/* if neither present in dest - fail */
|
||||
if (((strncmp(pAppSysTop, resolved_path, lenApplSys)) == SAME)
|
||||
@@ -298,7 +388,7 @@ checkLink(path)
|
||||
return;
|
||||
} else {
|
||||
fprintf(stdout,
|
||||
"FATAL ERROR - link '%s' must point to application system area or application shadow area or EPICS release\n\t dest='%s'\n", path, resolved_path);
|
||||
"\tFATAL ERROR - link '%s' must point to the application system area, \n\t application shadow area or an EPICS release\n\t\tdest='%s'\n", path, resolved_path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -317,7 +407,7 @@ dirwalk(dir, fcn)
|
||||
char buffer[MAXNAMLEN];
|
||||
if ((dfd = opendir(dir)) == NULL) {
|
||||
fprintf(stdout, "dirwalk: can't open %s\n", dir);
|
||||
return;
|
||||
return(-1);
|
||||
}
|
||||
strcpy(name, pAppSysTop);
|
||||
strcat(name, "/");
|
||||
@@ -396,7 +486,7 @@ initScriptFile()
|
||||
}
|
||||
if ((stat(pScriptFileName, &sb) == 0)) {
|
||||
fprintf(stderr,
|
||||
"\napStatusSync: - The previous output file '%s' still exists\n", pScriptFileName);
|
||||
"\nThe previous output file '%s' still exists!\n", pScriptFileName);
|
||||
fprintf(stderr,
|
||||
"Please remove the file and try again\n");
|
||||
fprintf(stderr,
|
||||
@@ -424,7 +514,7 @@ close (apRemoveScriptFp);
|
||||
return(0);
|
||||
}
|
||||
/****************************************************************************
|
||||
appendToScriptFile
|
||||
APPENDTOSCRIPTFILE
|
||||
****************************************************************************/
|
||||
static int
|
||||
appendToScriptFile(pstring)
|
||||
@@ -459,7 +549,9 @@ wrt_buf(fp, pstring, pfile)
|
||||
}
|
||||
postAmble()
|
||||
{
|
||||
fprintf(stdout,"\n\napStatusSync: ============>> ==>> ==>> ==>> Status Completed \n");
|
||||
fprintf(stdout,"===========================================================\n");
|
||||
fprintf(stdout,"Status Completed \n");
|
||||
fprintf(stdout,"===========================================================\n");
|
||||
fprintf(stdout,"When you are satisfied with the above status - continue\n");
|
||||
fprintf(stdout," else - correct the situation and run apStatusSync again\n");
|
||||
fprintf(stdout,"\ncontinue below\n");
|
||||
|
||||
Reference in New Issue
Block a user