weizhouapache commented on code in PR #10254:
URL: https://github.com/apache/cloudstack/pull/10254#discussion_r1927168211


##########
systemvm/debian/opt/cloud/bin/configure.py:
##########
@@ -932,6 +932,7 @@ def __htaccess(self, ip, folder, file):
         if os.path.exists(htaccessFile):
             fh = open(htaccessFile, "a+")
             self.__exflock(fh)
+            fh.seek(0)
             if entry not in fh.read():
                 fh.write(entry + '\n')

Review Comment:
   cc @DaanHoogland 
   quick test results
   
   - with `fh.read`
   ```
   root@r-1211-VM:~# cat /tmp/aa
   aaa
   bbb
   root@r-1211-VM:~# python3
   Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> fh=open("/tmp/aa","a+")
   >>> fh.seek(0)
   0
   >>> fh.read()
   'aaa\nbbb\n'
   >>> fh.write("ccc\n")
   4
   >>> fh.close()
   >>> 
   root@r-1211-VM:~# cat /tmp/aa 
   aaa
   bbb
   ccc
   ```
   
   - without `fh.read`
   
   ```
   root@r-1211-VM:~# python3
   Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> fh=open("/tmp/aa","a+")
   >>> fh.seek(0)
   0
   >>> fh.write("ddd\n")
   4
   >>> fh.close()
   >>> 
   root@r-1211-VM:~# cat /tmp/aa 
   aaa
   bbb
   ccc
   ddd
   ```
   
   no matter if `fh.read()` is called, the new entries are appended to the eof.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to