如何在tar中获取tar文件所需的路径

时间:2017-04-12 07:59:49

标签: go tar

我一直在使用此代码写入tar文件。我称之为 SELECT TOP 100 T1.Name, T1.permissionId FROM (SELECT top 100 n.Name, rp.* FROM dbo.[User] AS u JOIN dbo.UserRole AS ur ON ur.UserId = u.UserId JOIN dbo.ClientRole as cr on cr.RoleId = ur.RoleId JOIN dbo.Name as n2 on cr.NameId = n2.NameId JOIN dbo.RolePermissions AS rp on rp.RoleId = ur.RoleId JOIN dbo.SystemTaxonomy AS st on st.SystemTaxonomyId = rp.PermissionId JOIN dbo.Name AS n on st.NameId = n.NameId WHERE u.LoginName IN ('user1')) AS T1 JOIN (SELECT top 100 n1.Name, rp1.* FROM dbo.[User] AS u1 JOIN dbo.UserRole AS ur1 ON ur1.UserId = u1.UserId JOIN dbo.ClientRole as cr1 on cr1.RoleId = ur1.RoleId JOIN dbo.Name as n2 on cr1.NameId = n2.NameId JOIN dbo.RolePermissions AS rp1 on rp1.RoleId = ur1.RoleId JOIN dbo.SystemTaxonomy AS st1 on st1.SystemTaxonomyId = rp1.PermissionId JOIN dbo.Name AS n1 on st1.NameId = n1.NameId WHERE u1.LoginName IN ('user2')) AS T2 ON T1.permissionId = T2.permissionId ,其中err = retarIt(dirTopDebug, path)是我的tar文件(dirTopDebug)的路径,/tmp/abc.tar是我要添加的文件的路径(path)。当我解压缩生成的tar文件时,我发现/tmp/xyz/...个文件内部以abc.tar格式放置。但是我希望它们在/tmp/xyz/..之内的tar中,即没有xyz/...文件夹。

我该怎么做?

tmp

1 个答案:

答案 0 :(得分:1)

使用tar头中指定的名称。使用strings包的strings.LastIndex(或strings.Index)函数将部分分开,直到/ tmp。

因此,如果上面的TarGzWrite函数中的代码被修改如下,它就会按照你想要的方式工作(注意:你可能想用strings.Index替换下面的strings.LastIndex)。

$text2 = !empty($text2) ? "'".$text2."'":null;
$text1 = !empty($text1) ? "'".$text1."'":null;
$query = mysqli_query($this->db,"INSERT INTO `posts` (text1,text2, uid_fk,time) VALUES ($text1,$text2,'$uid','$time')");