Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-53588

[P4 Plugin] Shelve fails with 'tampered with after resolve' for utf8 files

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • p4-plugin
    • Jenkins LTS 2.121.1 on CentOS Linux release 7.3.1611 (Core)
      p4-plugin 1.8.15
      P4 Server version: P4D/LINUX26X86_64/2017.2/1622831 (2018/02/20)
      P4 Client on Windows 10

      Steps to reproduce:

      1. Create a new file with type <utf8>
      2. Branch that file
      3. Edit and submit changes to the original file
      4. Run a Jenkins pipeline job with steps similar to below:
      // helper method for creating a changelist
      def createChangelist(p4) {
      	def changelistId = -1
      	def changeForm = p4.fetch("change", "")
      	changeForm.put("Description", "Integrate")
      	def changeMsg = p4.save("change", changeForm)
      	def changeOutput = changeMsg[0].get("change")
      	if (changeOutput) {
      		def match = changeOutput =~ /Change (\d+)/
      		changelistId = match[0][1]
      	}
      	return changelistId
      }
      
      node {
      	// Define workspace
      	def view = "//depot/path/... //${P4_CLIENT}/depot/path..."
      	def spec = clientSpec(allwrite: false, backup: false, clobber: false, compress: false, line: 'LOCAL', locked: false, modtime: false, rmdir: false, 
      		serverID: '', streamName: '', type: 'WRITABLE', view: view)
      	def ws = manualSpec(charset: 'none', name: 'jenkins-${JOB_NAME}', spec: spec)
      
      	// Create object
      	def p4 = p4(credential: 'phooey', workspace: ws)
      	def clientName = p4.getClientName()
      
      	def sourceFile = "//depot/path/file1.txt"
      	def targetFile = "//depot/path/file2.txt"
      
      	try {
      		def changelistId
      		stage("Integrate") {
      			changelistId = createChangelist(p4)
      			p4.run("integ", "-c${changelistId}", sourceFile, targetFile)
      		}
      		stage("Resolve") {
      			p4.run("resolve", "-as", "//${clientName}/...")
      		}
      		stage("Shelve") {
      			def shelveMsg = p4.run("shelve", "-c${changelistId}", "//${clientName}/...")
      			echo(shelveMsg.toString())
      		}
      	} catch (ex) {
      		echo(ex.getMessage())
      	} finally {
      		p4.run("revert", "-w", "//${clientName}/...")
      	}
      }
      

      The p4 shelve command will fail and return the following error message:

      %clientFile% tampered with after resolve - edit or revert.
      

      Note: I was unable to reproduce this error using only P4Java in a simple test program.

          [JENKINS-53588] [P4 Plugin] Shelve fails with 'tampered with after resolve' for utf8 files

          Paul Allen added a comment -

          Does your file include a UTF8 BOM? Java may write the BOM, there might be a config option in p4java to change behaviour.

          Paul Allen added a comment - Does your file include a UTF8 BOM? Java may write the BOM, there might be a config option in p4java to change behaviour.

          Stuart Rowe added a comment -

          p4paul The Jenkins node has JVM option -Dcom.perforce.p4java.filesys.utf8bom=0 to prevent writing the BOM. However, I added an input step in between the resolve and shelve stages and noticed that the target file does have a BOM after the resolve which is unexpected.

          Stuart Rowe added a comment - p4paul The Jenkins node has JVM option -Dcom.perforce.p4java.filesys.utf8bom=0 to prevent writing the BOM. However, I added an input step in between the resolve and shelve stages and noticed that the target file does have a BOM after the resolve which is unexpected.

          Paul Allen added a comment -

          I'll raise a P4Java bug on resolve; good timing as we are planning to overhaul P4Java before the end off the year.

          Paul Allen added a comment - I'll raise a P4Java bug on resolve; good timing as we are planning to overhaul P4Java before the end off the year.

          Karl Wirth added a comment -

          Confirm that this is a P4JAVA bug. The BOM is added even if  '-Dcom.perforce.p4java.filesys.utf8bom=0 ' is set in the environment. I cannot reproduce the tamper error yest but it doesn't matter because the file is corrupt and I can see the MD5SUM no longer matches.

          Source:

          $ od -a test.txt 
          0000000   H   e   l   l   o  sp   W   o   r   l   d
          0000013
          

          Target:

          $ od -a test.txt 
          0000000   o   ;   ?   H   e   l   l   o  sp   W   o   r   l   d
          0000016
          

          Setup test in P4 ("p4 integ //depot/src/test2.txt //depot/src/test.txt").

          Very simple resolve code used:

          System.out.println("Run ExecMap Command");
          String[] execMapArgs = {"-as","//depot/src/test.txt"};
          List<Map<String, Object>> resultMaps = server.execMapCmdList("resolve",execMapArgs, null);
          System.out.println("\nCommand Output:");
          for ( Map myMap: resultMaps) {for (Object value: myMap.values()) {System.out.print(value);}}

           

           

          Karl Wirth added a comment - Confirm that this is a P4JAVA bug. The BOM is added even if  ' -Dcom.perforce.p4java.filesys.utf8bom=0 ' is set in the environment. I cannot reproduce the tamper error yest but it doesn't matter because the file is corrupt and I can see the MD5SUM no longer matches. Source: $ od -a test.txt 0000000 H e l l o sp W o r l d 0000013 Target: $ od -a test.txt 0000000 o ; ? H e l l o sp W o r l d 0000016 Setup test in P4 ("p4 integ //depot/src/test2.txt //depot/src/test.txt"). Very simple resolve code used: System .out.println( "Run ExecMap Command" ); String [] execMapArgs = { "-as" , " //depot/src/test.txt" }; List<Map< String , Object >> resultMaps = server.execMapCmdList( "resolve" ,execMapArgs, null ); System .out.println( "\nCommand Output:" ); for ( Map myMap: resultMaps) { for ( Object value: myMap.values()) { System .out.print(value);}}    

            p4paul Paul Allen
            stuartrowe Stuart Rowe
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: