Skip to content

Commit

Permalink
Fix typo to make build, and use a custom basename() function because
Browse files Browse the repository at this point in the history
the OS X stock function isn't reentrant.
  • Loading branch information
RJVB committed Sep 26, 2016
1 parent f7883b5 commit 5ca24b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .kdev4/afsctool_34.kdev4
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pattern=__pycache__
targets=2

[MakeBuilder]
Additional Options=--nice 10 -w VERBOSE=1 V=1
Additional Options=--nice 10 --MP -w VERBOSE=1 V=1
Default Make Environment Profile=KDE/MacPorts
Make Binary=wmake
Number Of Jobs=1
Expand Down
2 changes: 1 addition & 1 deletion ParallelProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ size_t filesInParallelProcessor(ParallelFileProcessor *p);
bool lockParallelProcessorIO(FileProcessor *worker);
// unlock the ioLock if it was previously locked by a call to lockParallelProcessorIO()
bool unLockParallelProcessorIO(FileProcessor *worker);
int currentParallelProcesorID(FileProcessor *worker);
int currentParallelProcessorID(FileProcessor *worker);
int runParallelProcessor(ParallelFileProcessor *p);
void stopParallelProcessor(ParallelFileProcessor *p);
struct folder_info *getParallelProcessorJobInfo(ParallelFileProcessor *p);
Expand Down
26 changes: 23 additions & 3 deletions afsctool.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ bool fileIsCompressable(const char *inFile, struct stat *inFileInfo)
&& (inFileInfo->st_flags & UF_COMPRESSED) == 0);
}

/*! Mac OS X basename() can modify the input string when not in 'legacy' mode on 10.6
* and indeed it does. So we use our own which doesn't, and also doesn't require internal
* storage.
*/
static const char *lbasename(const char *url)
{ const char *c = NULL;
if (url)
{
if ((c = strrchr( url, '/' )))
{
c++;
}
else
{
c = url;
}
}
return c;
}

#if SUPPORT_PARALLEL
void compressFile(const char *inFile, struct stat *inFileInfo, struct folder_info *folderinfo, void *worker )
#else
Expand Down Expand Up @@ -237,7 +257,7 @@ void compressFile(const char *inFile, struct stat *inFileInfo, struct folder_inf
char *infile, *inname = NULL;
if ((infile = strdup(inFile)))
{
inname = basename(infile);
inname = (char*) lbasename(infile);
// avoid filename overflow; assume 32 fixed template char for mkstemps
// just to be on the safe side (even in parallel mode).
if (strlen(inname) > 1024 - 32)
Expand All @@ -249,7 +269,7 @@ void compressFile(const char *inFile, struct stat *inFileInfo, struct folder_inf
// add the processor ID for the unlikely case that 2 threads try to backup a file with the same name
// at the same time, and mkstemps() somehow generates the same temp. name. I've seen it generate EEXIST
// errors which suggest that might indeed happen.
bkNameLen = asprintf(&backupName, "/tmp/afsctbk.%d.XXXXXX.%s", currentParallelProcesorID(worker), inname);
bkNameLen = asprintf(&backupName, "/tmp/afsctbk.%d.XXXXXX.%s", currentParallelProcessorID(worker), inname);
#else
bkNameLen = asprintf(&backupName, "/tmp/afsctbk.XXXXXX.%s", inname);
#endif
Expand All @@ -260,7 +280,7 @@ void compressFile(const char *inFile, struct stat *inFileInfo, struct folder_inf
xfree(infile);
goto bail;
}
if ((fd = mkstemps(backupName, strlen(inname)) < 0 || !(fp = fdopen(fd, "w")))
if ((fd = mkstemps(backupName, strlen(inname)+1)) < 0 || !(fp = fdopen(fd, "w")))
{
fprintf(stderr, "%s: error creating temporary backup file %s (%s)\n", inFile, backupName, strerror(errno));
xfree(infile);
Expand Down

0 comments on commit 5ca24b2

Please sign in to comment.