mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix some sloppiness in the new BufFileSize() and BufFileAppend() functions.
There were three related issues: * BufFileAppend() incorrectly reset the seek position on the 'source' file. As a result, if you had called BufFileRead() on the file before calling BufFileAppend(), it got confused, and subsequent calls would read/write at wrong position. * BufFileSize() did not work with files opened with BufFileOpenShared(). * FileGetSize() only worked on temporary files. To fix, change the way BufFileSize() works so that it works on shared files. Remove FileGetSize() altogether, as it's no longer needed. Remove buffilesize from TapeShare struct, as the leader process can simply call BufFileSize() to get the tape's size, there's no need to pass it through shared memory anymore. Discussion: https://www.postgresql.org/message-id/CAH2-WznEDYe_NZXxmnOfsoV54oFkTdMy7YLE2NPBLuttO96vTQ@mail.gmail.com
This commit is contained in:
		@@ -802,14 +802,24 @@ BufFileTellBlock(BufFile *file)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Return the current file size.  Counts any holes left behind by
 | 
			
		||||
 * BufFileViewAppend as part of the size.
 | 
			
		||||
 * Return the current file size.
 | 
			
		||||
 *
 | 
			
		||||
 * Counts any holes left behind by BufFileAppend as part of the size.
 | 
			
		||||
 * Returns -1 on error.
 | 
			
		||||
 */
 | 
			
		||||
off_t
 | 
			
		||||
BufFileSize(BufFile *file)
 | 
			
		||||
{
 | 
			
		||||
	off_t		lastFileSize;
 | 
			
		||||
 | 
			
		||||
	/* Get the size of the last physical file by seeking to end. */
 | 
			
		||||
	lastFileSize = FileSeek(file->files[file->numFiles - 1], 0, SEEK_END);
 | 
			
		||||
	if (lastFileSize < 0)
 | 
			
		||||
		return -1;
 | 
			
		||||
	file->offsets[file->numFiles - 1] = lastFileSize;
 | 
			
		||||
 | 
			
		||||
	return ((file->numFiles - 1) * (off_t) MAX_PHYSICAL_FILESIZE) +
 | 
			
		||||
		FileGetSize(file->files[file->numFiles - 1]);
 | 
			
		||||
		lastFileSize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -853,7 +863,7 @@ BufFileAppend(BufFile *target, BufFile *source)
 | 
			
		||||
	for (i = target->numFiles; i < newNumFiles; i++)
 | 
			
		||||
	{
 | 
			
		||||
		target->files[i] = source->files[i - target->numFiles];
 | 
			
		||||
		target->offsets[i] = 0L;
 | 
			
		||||
		target->offsets[i] = source->offsets[i - target->numFiles];
 | 
			
		||||
	}
 | 
			
		||||
	target->numFiles = newNumFiles;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user