@@ -142,21 +142,27 @@ protected void initFileSystem(URI uri)
142142
143143 @ Override
144144 public void flush () throws IOException {
145- super .flush ();
146- if (LOG .isDebugEnabled ()) {
147- LOG .debug ("Resetting permissions to '" + permissions + "'" );
148- }
149- if (!Shell .WINDOWS ) {
150- Files .setPosixFilePermissions (Paths .get (file .getCanonicalPath ()),
151- permissions );
152- } else {
153- // FsPermission expects a 10-character string because of the leading
154- // directory indicator, i.e. "drwx------". The JDK toString method returns
155- // a 9-character string, so prepend a leading character.
156- FsPermission fsPermission = FsPermission .valueOf (
157- "-" + PosixFilePermissions .toString (permissions ));
158- FileUtil .setPermission (file , fsPermission );
145+ try {
146+ super .getWriteLock ().lock ();
147+ file .createNewFile ();
148+ if (LOG .isDebugEnabled ()) {
149+ LOG .debug ("Resetting permissions to '" + permissions + "'" );
150+ }
151+ if (!Shell .WINDOWS ) {
152+ Files .setPosixFilePermissions (Paths .get (file .getCanonicalPath ()),
153+ permissions );
154+ } else {
155+ // FsPermission expects a 10-character string because of the leading
156+ // directory indicator, i.e. "drwx------". The JDK toString method returns
157+ // a 9-character string, so prepend a leading character.
158+ FsPermission fsPermission = FsPermission .valueOf (
159+ "-" + PosixFilePermissions .toString (permissions ));
160+ FileUtil .setPermission (file , fsPermission );
161+ }
162+ } finally {
163+ super .getWriteLock ().unlock ();
159164 }
165+ super .flush ();
160166 }
161167
162168 private static Set <PosixFilePermission > modeToPosixFilePermission (
0 commit comments