Index: fakeroot-1.32.2/config.h.in
===================================================================
--- fakeroot-1.32.2.orig/config.h.in
+++ fakeroot-1.32.2/config.h.in
@@ -144,6 +144,9 @@
 /* Define to 1 if you have the `renameat' function. */
 #undef HAVE_RENAMEAT
 
+/* Define to 1 if you have the `renameat2' function. */
+#undef HAVE_RENAMEAT2
+
 /* have the semun union */
 #undef HAVE_SEMUN_DEF
 
Index: fakeroot-1.32.2/configure.ac
===================================================================
--- fakeroot-1.32.2.orig/configure.ac
+++ fakeroot-1.32.2/configure.ac
@@ -360,7 +360,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   ],[ AC_MSG_RESULT([no])
   ])
 
-AC_CHECK_FUNCS(fchmodat fchownat fstatat mkdirat mknodat openat renameat unlinkat lchmod fgetattrlist)
+AC_CHECK_FUNCS(fchmodat fchownat fstatat mkdirat mknodat openat renameat renameat2 unlinkat lchmod fgetattrlist)
 
 save_LIBS="$LIBS"
 # Linux
Index: fakeroot-1.32.2/libfakeroot.c
===================================================================
--- fakeroot-1.32.2.orig/libfakeroot.c
+++ fakeroot-1.32.2/libfakeroot.c
@@ -1382,6 +1382,29 @@ int renameat(int olddir_fd, const char *
   return 0;
 }
 #endif /* HAVE_RENAMEAT */
+#ifdef HAVE_RENAMEAT2
+int renameat2(int olddir_fd, const char *oldpath,
+              int newdir_fd, const char *newpath, unsigned int flags){
+  int r,s;
+  INT_STRUCT_STAT st;
+
+  /* If newpath points to an existing file, that file will be
+     unlinked.   Make sure we tell the faked daemon about this! */
+
+  /* we need the st_new struct in order to inform faked about the
+     (possible) unlink of the file */
+
+  r=INT_NEXT_FSTATAT(newdir_fd, newpath, &st, AT_SYMLINK_NOFOLLOW);
+
+  s=next_renameat2(olddir_fd, oldpath, newdir_fd, newpath, flags);
+  if(s)
+    return -1;
+  if(!r)
+    INT_SEND_STAT(&st,unlink_func);
+
+  return 0;
+}
+#endif /* HAVE_RENAMEAT2 */
 #endif /* HAVE_FSTATAT */
 
 
Index: fakeroot-1.32.2/wrapfunc.inp
===================================================================
--- fakeroot-1.32.2.orig/wrapfunc.inp
+++ fakeroot-1.32.2/wrapfunc.inp
@@ -203,6 +203,9 @@ mkdirat;int;(int dir_fd, const char *pat
 #ifdef HAVE_RENAMEAT
 renameat;int;(int olddir_fd, const char *oldpath, int newdir_fd, const char *newpath);(olddir_fd, oldpath, newdir_fd, newpath)
 #endif /* HAVE_RENAMEAT */
+#ifdef HAVE_RENAMEAT2
+renameat2;int;(int olddir_fd, const char *oldpath, int newdir_fd, const char *newpath, unsigned int flags);(olddir_fd, oldpath, newdir_fd, newpath, flags)
+#endif /* HAVE_RENAMEAT2 */
 #ifdef HAVE_UNLINKAT
 unlinkat;int;(int dir_fd, const char *pathname, int flags);(dir_fd, pathname, flags)
 #endif /* HAVE_UNLINKAT */
